home *** CD-ROM | disk | FTP | other *** search
/ Die Ultimative Software-P…i Collection 1996 & 1997 / Die Ultimative Software-Pakete CD-ROM fur Atari Collection 1996 & 1997.iso / g / gnu_c / gdb36p4b.zoo / gdb.info < prev    next >
Encoding:
GNU Info File  |  1993-10-05  |  141.2 KB  |  3,526 lines

  1. This is Info file gdb.info, produced by Makeinfo-1.55 from the input
  2. file gdb.texinfo.
  3.  
  4.    This file documents the GNU debugger GDB.
  5.  
  6.    Copyright (C) 1988, 1989 Free Software Foundation, Inc.
  7.  
  8.    Permission is granted to make and distribute verbatim copies of this
  9. manual provided the copyright notice and this permission notice are
  10. preserved on all copies.
  11.  
  12.    Permission is granted to copy and distribute modified versions of
  13. this manual under the conditions for verbatim copying, provided also
  14. that the section entitled "GNU General Public License" is included
  15. exactly as in the original, and provided that the entire resulting
  16. derived work is distributed under the terms of a permission notice
  17. identical to this one.
  18.  
  19.    Permission is granted to copy and distribute translations of this
  20. manual into another language, under the above conditions for modified
  21. versions, except that the section entitled "GNU General Public License"
  22. may be included in a translation approved by the author instead of in
  23. the original English.
  24.  
  25. File: gdb.info,  Node: Top,  Next: Top,  Prev: Top,  Up: (DIR)
  26.  
  27. Summary of GDB
  28. **************
  29.  
  30.    The purpose of a debugger such as GDB is to allow you to execute
  31. another program while examining what is going on inside it.  We call
  32. the other program "your program" or "the program being debugged".
  33.  
  34.    GDB can do four kinds of things (plus other things in support of
  35. these):
  36.  
  37.   1. Start the program, specifying anything that might affect its
  38.      behavior.
  39.  
  40.   2. Make the program stop on specified conditions.
  41.  
  42.   3. Examine what has happened, when the program has stopped, so that
  43.      you can see bugs happen.
  44.  
  45.   4. Change things in the program, so you can correct the effects of
  46.      one bug and go on to learn about another without having to
  47.      recompile first.
  48.  
  49.    GDB can be used to debug programs written in C and C++.  Pascal
  50. support is being implemented, and Fortran support will be added when a
  51. GNU Fortran compiler is written.
  52.  
  53. * Menu:
  54.  
  55. * License::    The GNU General Public License gives you permission
  56.            to redistribute GDB on certain terms; and also
  57.            explains that there is no warranty.
  58. * User Interface::      GDB command syntax and input and output conventions.
  59. * Files::      Specifying files for GDB to operate on.
  60. * Options::    GDB arguments and options.
  61. * Compilation::Compiling your program so you can debug it.
  62. * Running::    Running your program under GDB.
  63. * Stopping::   Making your program stop.  Why it may stop.  What to do then.
  64. * Stack::      Examining your program's stack.
  65. * Source::     Examining your program's source files.
  66. * Data::       Examining data in your program.
  67. * Symbols::    Examining the debugger's symbol table.
  68. * Altering::   Altering things in your program.
  69. * Sequences::  Canned command sequences for repeated use.
  70. * Emacs::      Using GDB through GNU Emacs.
  71. * Remote::     Remote kernel debugging across a serial line.
  72. * Commands::   Index of GDB commands.
  73. * Concepts::   Index of GDB concepts.
  74.  
  75. File: gdb.info,  Node: License,  Next: User Interface,  Prev: Top,  Up: Top
  76.  
  77. GNU GENERAL PUBLIC LICENSE
  78. **************************
  79.  
  80.                        Version 1, February 1989
  81.  
  82.      Copyright (C) 1989 Free Software Foundation, Inc.
  83.      675 Mass Ave, Cambridge, MA 02139, USA
  84.      
  85.      Everyone is permitted to copy and distribute verbatim copies
  86.      of this license document, but changing it is not allowed.
  87.  
  88. Preamble
  89. ========
  90.  
  91.    The license agreements of most software companies try to keep users
  92. at the mercy of those companies.  By contrast, our General Public
  93. License is intended to guarantee your freedom to share and change free
  94. software--to make sure the software is free for all its users.  The
  95. General Public License applies to the Free Software Foundation's
  96. software and to any other program whose authors commit to using it.
  97. You can use it for your programs, too.
  98.  
  99.    When we speak of free software, we are referring to freedom, not
  100. price.  Specifically, the General Public License is designed to make
  101. sure that you have the freedom to give away or sell copies of free
  102. software, that you receive source code or can get it if you want it,
  103. that you can change the software or use pieces of it in new free
  104. programs; and that you know you can do these things.
  105.  
  106.    To protect your rights, we need to make restrictions that forbid
  107. anyone to deny you these rights or to ask you to surrender the rights.
  108. These restrictions translate to certain responsibilities for you if you
  109. distribute copies of the software, or if you modify it.
  110.  
  111.    For example, if you distribute copies of a such a program, whether
  112. gratis or for a fee, you must give the recipients all the rights that
  113. you have.  You must make sure that they, too, receive or can get the
  114. source code.  And you must tell them their rights.
  115.  
  116.    We protect your rights with two steps: (1) copyright the software,
  117. and (2) offer you this license which gives you legal permission to copy,
  118. distribute and/or modify the software.
  119.  
  120.    Also, for each author's protection and ours, we want to make certain
  121. that everyone understands that there is no warranty for this free
  122. software.  If the software is modified by someone else and passed on, we
  123. want its recipients to know that what they have is not the original, so
  124. that any problems introduced by others will not reflect on the original
  125. authors' reputations.
  126.  
  127.    The precise terms and conditions for copying, distribution and
  128. modification follow.
  129.  
  130.                          TERMS AND CONDITIONS
  131.  
  132.   1. This License Agreement applies to any program or other work which
  133.      contains a notice placed by the copyright holder saying it may be
  134.      distributed under the terms of this General Public License.  The
  135.      "Program", below, refers to any such program or work, and a "work
  136.      based on the Program" means either the Program or any work
  137.      containing the Program or a portion of it, either verbatim or with
  138.      modifications.  Each licensee is addressed as "you".
  139.  
  140.   2. You may copy and distribute verbatim copies of the Program's source
  141.      code as you receive it, in any medium, provided that you
  142.      conspicuously and appropriately publish on each copy an
  143.      appropriate copyright notice and disclaimer of warranty; keep
  144.      intact all the notices that refer to this General Public License
  145.      and to the absence of any warranty; and give any other recipients
  146.      of the Program a copy of this General Public License along with
  147.      the Program.  You may charge a fee for the physical act of
  148.      transferring a copy.
  149.  
  150.   3. You may modify your copy or copies of the Program or any portion of
  151.      it, and copy and distribute such modifications under the terms of
  152.      Paragraph 1 above, provided that you also do the following:
  153.  
  154.         * cause the modified files to carry prominent notices stating
  155.           that you changed the files and the date of any change; and
  156.  
  157.         * cause the whole of any work that you distribute or publish,
  158.           that in whole or in part contains the Program or any part
  159.           thereof, either with or without modifications, to be licensed
  160.           at no charge to all third parties under the terms of this
  161.           General Public License (except that you may choose to grant
  162.           warranty protection to some or all third parties, at your
  163.           option).
  164.  
  165.         * If the modified program normally reads commands interactively
  166.           when run, you must cause it, when started running for such
  167.           interactive use in the simplest and most usual way, to print
  168.           or display an announcement including an appropriate copyright
  169.           notice and a notice that there is no warranty (or else,
  170.           saying that you provide a warranty) and that users may
  171.           redistribute the program under these conditions, and telling
  172.           the user how to view a copy of this General Public License.
  173.  
  174.         * You may charge a fee for the physical act of transferring a
  175.           copy, and you may at your option offer warranty protection in
  176.           exchange for a fee.
  177.  
  178.      Mere aggregation of another independent work with the Program (or
  179.      its derivative) on a volume of a storage or distribution medium
  180.      does not bring the other work under the scope of these terms.
  181.  
  182.   4. You may copy and distribute the Program (or a portion or
  183.      derivative of it, under Paragraph 2) in object code or executable
  184.      form under the terms of Paragraphs 1 and 2 above provided that you
  185.      also do one of the following:
  186.  
  187.         * accompany it with the complete corresponding machine-readable
  188.           source code, which must be distributed under the terms of
  189.           Paragraphs 1 and 2 above; or,
  190.  
  191.         * accompany it with a written offer, valid for at least three
  192.           years, to give any third party free (except for a nominal
  193.           charge for the cost of distribution) a complete
  194.           machine-readable copy of the corresponding source code, to be
  195.           distributed under the terms of Paragraphs 1 and 2 above; or,
  196.  
  197.         * accompany it with the information you received as to where the
  198.           corresponding source code may be obtained.  (This alternative
  199.           is allowed only for noncommercial distribution and only if you
  200.           received the program in object code or executable form alone.)
  201.  
  202.      Source code for a work means the preferred form of the work for
  203.      making modifications to it.  For an executable file, complete
  204.      source code means all the source code for all modules it contains;
  205.      but, as a special exception, it need not include source code for
  206.      modules which are standard libraries that accompany the operating
  207.      system on which the executable file runs, or for standard header
  208.      files or definitions files that accompany that operating system.
  209.  
  210.   5. You may not copy, modify, sublicense, distribute or transfer the
  211.      Program except as expressly provided under this General Public
  212.      License.  Any attempt otherwise to copy, modify, sublicense,
  213.      distribute or transfer the Program is void, and will automatically
  214.      terminate your rights to use the Program under this License.
  215.      However, parties who have received copies, or rights to use
  216.      copies, from you under this General Public License will not have
  217.      their licenses terminated so long as such parties remain in full
  218.      compliance.
  219.  
  220.   6. By copying, distributing or modifying the Program (or any work
  221.      based on the Program) you indicate your acceptance of this license
  222.      to do so, and all its terms and conditions.
  223.  
  224.   7. Each time you redistribute the Program (or any work based on the
  225.      Program), the recipient automatically receives a license from the
  226.      original licensor to copy, distribute or modify the Program
  227.      subject to these terms and conditions.  You may not impose any
  228.      further restrictions on the recipients' exercise of the rights
  229.      granted herein.
  230.  
  231.   8. The Free Software Foundation may publish revised and/or new
  232.      versions of the General Public License from time to time.  Such
  233.      new versions will be similar in spirit to the present version, but
  234.      may differ in detail to address new problems or concerns.
  235.  
  236.      Each version is given a distinguishing version number.  If the
  237.      Program specifies a version number of the license which applies to
  238.      it and "any later version", you have the option of following the
  239.      terms and conditions either of that version or of any later
  240.      version published by the Free Software Foundation.  If the Program
  241.      does not specify a version number of the license, you may choose
  242.      any version ever published by the Free Software Foundation.
  243.  
  244.   9. If you wish to incorporate parts of the Program into other free
  245.      programs whose distribution conditions are different, write to the
  246.      author to ask for permission.  For software which is copyrighted
  247.      by the Free Software Foundation, write to the Free Software
  248.      Foundation; we sometimes make exceptions for this.  Our decision
  249.      will be guided by the two goals of preserving the free status of
  250.      all derivatives of our free software and of promoting the sharing
  251.      and reuse of software generally.
  252.  
  253.                                 NO WARRANTY
  254.  
  255.  10. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO
  256.      WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE
  257.      LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
  258.      HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
  259.      WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT
  260.      NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  261.      FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE
  262.      QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
  263.      PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY
  264.      SERVICING, REPAIR OR CORRECTION.
  265.  
  266.  11. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
  267.      WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY
  268.      MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE
  269.      LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
  270.      INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
  271.      INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
  272.      DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU
  273.      OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY
  274.      OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
  275.      ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  276.  
  277.                       END OF TERMS AND CONDITIONS
  278.  
  279. Appendix: How to Apply These Terms to Your New Programs
  280. =======================================================
  281.  
  282.    If you develop a new program, and you want it to be of the greatest
  283. possible use to humanity, the best way to achieve this is to make it
  284. free software which everyone can redistribute and change under these
  285. terms.
  286.  
  287.    To do so, attach the following notices to the program.  It is safest
  288. to attach them to the start of each source file to most effectively
  289. convey the exclusion of warranty; and each file should have at least the
  290. "copyright" line and a pointer to where the full notice is found.
  291.  
  292.      ONE LINE TO GIVE THE PROGRAM'S NAME AND A BRIEF IDEA OF WHAT IT DOES.
  293.      Copyright (C) 19YY  NAME OF AUTHOR
  294.      
  295.      This program is free software; you can redistribute it and/or modify
  296.      it under the terms of the GNU General Public License as published by
  297.      the Free Software Foundation; either version 1, or (at your option)
  298.      any later version.
  299.      
  300.      This program is distributed in the hope that it will be useful,
  301.      but WITHOUT ANY WARRANTY; without even the implied warranty of
  302.      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  303.      GNU General Public License for more details.
  304.      
  305.      You should have received a copy of the GNU General Public License
  306.      along with this program; if not, write to the Free Software
  307.      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  308.  
  309.    Also add information on how to contact you by electronic and paper
  310. mail.
  311.  
  312.    If the program is interactive, make it output a short notice like
  313. this when it starts in an interactive mode:
  314.  
  315.      Gnomovision version 69, Copyright (C) 19YY NAME OF AUTHOR
  316.      Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
  317.      This is free software, and you are welcome to redistribute it
  318.      under certain conditions; type `show c' for details.
  319.  
  320.    The hypothetical commands `show w' and `show c' should show the
  321. appropriate parts of the General Public License.  Of course, the
  322. commands you use may be called something other than `show w' and `show
  323. c'; they could even be mouse-clicks or menu items--whatever suits your
  324. program.
  325.  
  326.    You should also get your employer (if you work as a programmer) or
  327. your school, if any, to sign a "copyright disclaimer" for the program,
  328. if necessary.  Here a sample; alter the names:
  329.  
  330.      Yoyodyne, Inc., hereby disclaims all copyright interest in the
  331.      program `Gnomovision' (a program to direct compilers to make passes
  332.      at assemblers) written by James Hacker.
  333.      
  334.      SIGNATURE OF TY COON, 1 April 1989
  335.      Ty Coon, President of Vice
  336.  
  337.    That's all there is to it!
  338.  
  339. File: gdb.info,  Node: User Interface,  Next: Files,  Prev: License,  Up: Top
  340.  
  341. GDB Input and Output Conventions
  342. ********************************
  343.  
  344.    GDB is invoked with the shell command `gdb'.  Once started, it reads
  345. commands from the terminal until you tell it to exit.
  346.  
  347.    A GDB command is a single line of input.  There is no limit on how
  348. long it can be.  It starts with a command name, which is followed by
  349. arguments whose meaning depends on the command name.  For example, the
  350. command `step' accepts an argument which is the number of times to step,
  351. as in `step 5'.  You can also use the `step' command with no arguments.
  352. Some command names do not allow any arguments.
  353.  
  354.    GDB command names may always be abbreviated if the abbreviation is
  355. unambiguous.  Sometimes even ambiguous abbreviations are allowed; for
  356. example, `s' is specially defined as equivalent to `step' even though
  357. there are other commands whose names start with `s'.  Possible command
  358. abbreviations are often stated in the documentation of the individual
  359. commands.
  360.  
  361.    A blank line as input to GDB means to repeat the previous command
  362. verbatim.  Certain commands do not allow themselves to be repeated this
  363. way; these are commands for which unintentional repetition might cause
  364. trouble and which you are unlikely to want to repeat.  Certain others
  365. (`list' and `x') act differently when repeated because that is more
  366. useful.
  367.  
  368.    A line of input starting with `#' is a comment; it does nothing.
  369. This is useful mainly in command files (*Note Command Files::).
  370.  
  371.    GDB indicates its readiness to read a command by printing a string
  372. called the "prompt".  This string is normally `(gdb)'.  You can change
  373. the prompt string with the `set prompt' command.  For instance, when
  374. debugging GDB with GDB, it is useful to change the prompt in one of the
  375. GDBs so that you tell which one you are talking to.
  376.  
  377. `set prompt NEWPROMPT'
  378.      Directs GDB to use NEWPROMPT as its prompt string henceforth.
  379.  
  380.    To exit GDB, use the `quit' command (abbreviated `q').  `Ctrl-c'
  381. will not exit from GDB, but rather will terminate the action of any GDB
  382. command that is in progress and return to GDB command level.  It is
  383. safe to type `Ctrl-c' at any time because GDB does not allow it to take
  384. effect until a time when it is safe.
  385.  
  386.    Certain commands to GDB may produce large amounts of information
  387. output to the screen.  To help you read all of it, GDB pauses and asks
  388. you for input at the end of each page of output.  Type RET when you want
  389. to continue the output.  Normally GDB knows the size of the screen from
  390. on the termcap data base together with the value of the `TERM'
  391. environment variable; if this is not correct, you can override it with
  392. the `set screensize' command:
  393.  
  394. `set screensize LPP'
  395. `set screensize LPP CPL'
  396.      Specify a screen height of LPP lines and (optionally) a width of
  397.      CPL characters.  If you omit CPL, the width does not change.
  398.  
  399.      If you specify a height of zero lines, GDB will not pause during
  400.      output no matter how long the output is.  This is useful if output
  401.      is to a file or to an editor buffer.
  402.  
  403.    Also, GDB may at times produce more information about its own
  404. workings than is of interest to the user.  Some of these informational
  405. messages can be turned on and off with the `set verbose' command:
  406.  
  407. `set verbose off'
  408.      Disables GDB's output of certain informational messages.
  409.  
  410. `set verbose on'
  411.      Re-enables GDB's output of certain informational messages.
  412.  
  413.    Currently, the messages controlled by `set verbose' are those which
  414. announce that the symbol table for a source file is being read (*note
  415. File Commands::., in the description of the command `symbol-file').
  416.  
  417. File: gdb.info,  Node: Files,  Next: Compilation,  Prev: User Interface,  Up: Top
  418.  
  419. Specifying GDB's Files
  420. **********************
  421.  
  422.    GDB needs to know the file name of the program to be debugged, both
  423. in order to read its symbol table and in order to start the program.  To
  424. debug a core dump of a previous run, GDB must be told the file name of
  425. the core dump.
  426.  
  427. * Menu:
  428.  
  429. * Arguments: File Arguments.   Specifying files with arguments
  430.                                 (when you start GDB).
  431. * Commands: File Commands.     Specifying files with GDB commands.
  432.  
  433. File: gdb.info,  Node: File Arguments,  Next: File Commands,  Prev: Files,  Up: Files
  434.  
  435. Specifying Files with Arguments
  436. ===============================
  437.  
  438.    The usual way to specify the executable and core dump file names is
  439. with two command arguments given when you start GDB.  The first
  440. argument is used as the file for execution and symbols, and the second
  441. argument (if any) is used as the core dump file name.  Thus,
  442.  
  443.      gdb progm core
  444.  
  445. specifies `progm' as the executable program and `core' as a core dump
  446. file to examine.  (You do not need to have a core dump file if what you
  447. plan to do is debug the program interactively.)
  448.  
  449.    *Note Options::, for full information on options and arguments for
  450. invoking GDB.
  451.  
  452. File: gdb.info,  Node: File Commands,  Prev: File Arguments,  Up: Files
  453.  
  454. Specifying Files with Commands
  455. ==============================
  456.  
  457.    Usually you specify the files for GDB to work with by giving
  458. arguments when you invoke GDB.  But occasionally it is necessary to
  459. change to a different file during a GDB session.  Or you may run GDB
  460. and forget to specify the files you want to use.  In these situations
  461. the GDB commands to specify new files are useful.
  462.  
  463. `exec-file FILENAME'
  464.      Specify that the program to be run is found in FILENAME.  If you
  465.      do not specify a directory and the file is not found in GDB's
  466.      working directory, GDB will use the environment variable `PATH' as
  467.      a list of directories to search, just as the shell does when
  468.      looking for a program to run.
  469.  
  470. `symbol-file FILENAME'
  471.      Read symbol table information from file FILENAME.  `PATH' is
  472.      searched when necessary.  Most of the time you will use both the
  473.      `exec-file' and `symbol-file' commands on the same file.
  474.  
  475.      `symbol-file' with no argument clears out GDB's symbol table.
  476.  
  477.      The `symbol-file' command does not actually read the symbol table
  478.      in full right away.  Instead, it scans the symbol table quickly to
  479.      find which source files and which symbols are present.  The
  480.      details are read later, one source file at a time, when they are
  481.      needed.
  482.  
  483.      The purpose of this two-stage reading strategy is to make GDB
  484.      start up faster.  For the most part, it is invisible except for
  485.      occasional messages telling you that the symbol table details for
  486.      a particular source file are being read.  (The `set verbose'
  487.      command controls whether these messages are printed; *note User
  488.      Interface::.).
  489.  
  490.      However, you will sometimes see in backtraces lines for functions
  491.      in source files whose data has not been read in; these lines omit
  492.      some of the information, such as argument values, which cannot be
  493.      printed without full details of the symbol table.
  494.  
  495.      When the symbol table is stored in COFF format, `symbol-file' does
  496.      read the symbol table data in full right away.  We haven't
  497.      bothered to implement the two-stage strategy for COFF.
  498.  
  499. `core-file FILENAME'
  500.      Specify the whereabouts of a core dump file to be used as the
  501.      "contents of memory".  Note that the core dump contains only the
  502.      writable parts of memory; the read-only parts must come from the
  503.      executable file.
  504.  
  505.      `core-file' with no argument specifies that no core file is to be
  506.      used.
  507.  
  508.      Note that the core file is ignored when your program is actually
  509.      running under GDB.  So, if you have been running the program and
  510.      you wish to debug a core file instead, you must kill the
  511.      subprocess in which the program is running.  To do this, use the
  512.      `kill' command (*note Kill Process::.).
  513.  
  514. `add-file FILENAME ADDRESS'
  515.      The `add-file' command reads additional symbol table information
  516.      from the file FILENAME.  You would use this when that file has
  517.      been dynamically loaded into the program that is running.  ADDRESS
  518.      should be the memory address at which the file has been loaded;
  519.      GDB cannot figure this out for itself.
  520.  
  521.      The symbol table of the file FILENAME is added to the symbol table
  522.      originally read with the `symbol-file' command.  You can use the
  523.      `add-file' command any number of times; the new symbol data thus
  524.      read keeps adding to the old.  The `symbol-file' command forgets
  525.      all the symbol data GDB has read; that is the only time symbol
  526.      data is forgotten in GDB.
  527.  
  528. `info files'
  529.      Print the names of the executable and core dump files currently in
  530.      use by GDB, and the file from which symbols were loaded.
  531.  
  532.    While all three file-specifying commands allow both absolute and
  533. relative file names as arguments, GDB always converts the file name to
  534. an absolute one and remembers it that way.
  535.  
  536.    The `symbol-file' command causes GDB to forget the contents of its
  537. convenience variables, the value history, and all breakpoints and
  538. auto-display expressions.  This is because they may contain pointers to
  539. the internal data recording symbols and data types, which are part of
  540. the old symbol table data being discarded inside GDB.
  541.  
  542. File: gdb.info,  Node: Compilation,  Next: Running,  Prev: Files,  Up: Top
  543.  
  544. Compiling Your Program for Debugging
  545. ************************************
  546.  
  547.    In order to debug a program effectively, you need to ask for
  548. debugging information when you compile it.  This information in the
  549. object file describes the data type of each variable or function and
  550. the correspondence between source line numbers and addresses in the
  551. executable code.
  552.  
  553.    To request debugging information, specify the `-g' option when you
  554. run the compiler.
  555.  
  556.    The Unix C compiler is unable to handle the `-g' and `-O' options
  557. together.  This means that you cannot ask for optimization if you ask
  558. for debugger information.
  559.  
  560.    The GNU C compiler supports `-g' with or without `-O', making it
  561. possible to debug optimized code.  We recommend that you *always* use
  562. `-g' whenever you compile a program.  You may think the program is
  563. correct, but there's no sense in pushing your luck.
  564.  
  565.    GDB no longer supports the debugging information produced by giving
  566. the GNU C compiler the `-gg' option, so do not use this option.
  567.  
  568. File: gdb.info,  Node: Running,  Next: Stopping,  Prev: Compilation,  Up: Top
  569.  
  570. Running Your Program Under GDB
  571. ******************************
  572.  
  573.    To start your program under GDB, use the `run' command.  The program
  574. must already have been specified using the `exec-file' command or with
  575. an argument to GDB (*note Files::.); what `run' does is create an
  576. inferior process, load the program into it, and set it in motion.
  577.  
  578.    The execution of a program is affected by certain information it
  579. receives from its superior.  GDB provides ways to specify this
  580. information, which you must do before starting the program.  (You can
  581. change it after starting the program, but such changes do not affect
  582. the program unless you start it over again.)  This information may be
  583. divided into three categories:
  584.  
  585. The arguments.
  586.      You specify the arguments to give the program as the arguments of
  587.      the `run' command.
  588.  
  589. The environment.
  590.      The program normally inherits its environment from GDB, but you can
  591.      use the GDB commands `set environment' and `unset environment' to
  592.      change parts of the environment that will be given to the program.
  593.  
  594. The working directory.
  595.      The program inherits its working directory from GDB.  You can set
  596.      GDB's working directory with the `cd' command in GDB.
  597.  
  598.    After the `run' command, the debugger does nothing but wait for your
  599. program to stop.  *Note Stopping::.
  600.  
  601.    Note that once your program has been started by the `run' command,
  602. you may evaluate expressions that involve calls to functions in the
  603. inferior.  *Note Expressions::.  If you wish to evaluate a function
  604. simply for its side affects, you may use the `set' command.  *Note
  605. Assignment::.
  606.  
  607. * Menu:
  608.  
  609. * Arguments::          Specifying the arguments for your program.
  610. * Environment::        Specifying the environment for your program.
  611. * Working Directory::  Specifying the working directory for giving
  612.                        to your program when it is run.
  613. * Input/Output::       Specifying the program's standard input and output.
  614. * Attach::             Debugging a process started outside GDB.
  615. * Kill Process::       Getting rid of the child process running your program.
  616.  
  617. File: gdb.info,  Node: Arguments,  Next: Environment,  Prev: Running,  Up: Running
  618.  
  619. Your Program's Arguments
  620. ========================
  621.  
  622.    The arguments to your program are specified by the arguments of the
  623. `run' command.  They are passed to a shell, which expands wildcard
  624. characters and performs redirection of I/O, and thence to the program.
  625.  
  626.    `run' with no arguments uses the same arguments used by the previous
  627. `run'.
  628.  
  629.    The command `set args' can be used to specify the arguments to be
  630. used the next time the program is run.  If `set args' has no arguments,
  631. it means to use no arguments the next time the program is run.  If you
  632. have run your program with arguments and want to run it again with no
  633. arguments, this is the only way to do so.
  634.  
  635. File: gdb.info,  Node: Environment,  Next: Working Directory,  Prev: Arguments,  Up: Running
  636.  
  637. Your Program's Environment
  638. ==========================
  639.  
  640.    The "environment" consists of a set of "environment variables" and
  641. their values.  Environment variables conventionally record such things
  642. as your user name, your home directory, your terminal type, and your
  643. search path for programs to run.  Usually you set up environment
  644. variables with the shell and they are inherited by all the other
  645. programs you run.  When debugging, it can be useful to try running the
  646. program with different environments without having to start the
  647. debugger over again.
  648.  
  649. `info environment VARNAME'
  650.      Print the value of environment variable VARNAME to be given to
  651.      your program when it is started.  This command can be abbreviated
  652.      `i env VARNAME'.
  653.  
  654. `info environment'
  655.      Print the names and values of all environment variables to be
  656.      given to your program when it is started.  This command can be
  657.      abbreviated `i env'.
  658.  
  659. `set environment VARNAME VALUE'
  660. `set environment VARNAME = VALUE'
  661.      Sets environment variable VARNAME to VALUE, for your program only,
  662.      not for GDB itself.  VALUE may be any string; the values of
  663.      environment variables are just strings, and any interpretation is
  664.      supplied by your program itself.  The VALUE parameter is optional;
  665.      if it is eliminated, the variable is set to a null value.  This
  666.      command can be abbreviated as short as `set e'.
  667.  
  668.      For example, this command:
  669.  
  670.           set env USER = foo
  671.  
  672.      tells the program, when subsequently run, to assume it is being run
  673.      on behalf of the user named `foo'.
  674.  
  675. `delete environment VARNAME'
  676. `unset environment VARNAME'
  677.      Remove variable VARNAME from the environment to be passed to your
  678.      program.  This is different from `set env VARNAME =' because
  679.      `delete environment' leaves the variable with no value, which is
  680.      distinguishable from an empty value.  This command can be
  681.      abbreviated `d e'.
  682.  
  683. File: gdb.info,  Node: Working Directory,  Next: Input/Output,  Prev: Environment,  Up: Running
  684.  
  685. Your Program's Working Directory
  686. ================================
  687.  
  688.    Each time you start your program with `run', it inherits its working
  689. directory from the current working directory of GDB.  GDB's working
  690. directory is initially whatever it inherited from its parent process
  691. (typically the shell), but you can specify a new working directory in
  692. GDB with the `cd' command.
  693.  
  694.    The GDB working directory also serves as a default for the commands
  695. that specify files for GDB to operate on.  *Note Files::.
  696.  
  697. `cd DIRECTORY'
  698.      Set GDB's working directory to DIRECTORY.
  699.  
  700. `pwd'
  701.      Print GDB's working directory.
  702.  
  703. File: gdb.info,  Node: Input/Output,  Next: Attach,  Prev: Working Directory,  Up: Running
  704.  
  705. Your Program's Input and Output
  706. ===============================
  707.  
  708.    By default, the program you run under GDB does input and output to
  709. the same terminal that GDB uses.
  710.  
  711.    You can redirect the program's input and/or output using `sh'-style
  712. redirection commands in the `run' command.  For example,
  713.  
  714.      run > outfile
  715.  
  716. starts the program, diverting its output to the file `outfile'.
  717.  
  718.    Another way to specify where the program should do input and output
  719. is with the `tty' command.  This command accepts a file name as
  720. argument, and causes this file to be the default for future `run'
  721. commands.  It also resets the controlling terminal for the child
  722. process, for future `run' commands.  For example,
  723.  
  724.      tty /dev/ttyb
  725.  
  726. directs that processes started with subsequent `run' commands default
  727. to do input and output on the terminal `/dev/ttyb' and have that as
  728. their controlling terminal.
  729.  
  730.    An explicit redirection in `run' overrides the `tty' command's
  731. effect on input/output redirection, but not its effect on the
  732. controlling terminal.
  733.  
  734.    When you use the `tty' command or redirect input in the `run'
  735. command, only the *input for your program* is affected.  The input for
  736. GDB still comes from your terminal.
  737.  
  738. File: gdb.info,  Node: Attach,  Next: Kill Process,  Prev: Input/Output,  Up: Running
  739.  
  740. Debugging an Already-Running Process
  741. ====================================
  742.  
  743.    Some operating systems allow GDB to debug an already-running process
  744. that was started outside of GDB.  To do this, you use the `attach'
  745. command instead of the `run' command.
  746.  
  747.    The `attach' command requires one argument, which is the process-id
  748. of the process you want to debug.  (The usual way to find out the
  749. process-id of the process is with the `ps' utility.)
  750.  
  751.    The first thing GDB does after arranging to debug the process is to
  752. stop it.  You can examine and modify an attached process with all the
  753. GDB commands that ordinarily available when you start processes with
  754. `run'.  You can insert breakpoints; you can step and continue; you can
  755. modify storage.  If you would rather the process continue running, you
  756. may use the `continue' command after attaching GDB to the process.
  757.  
  758.    When you have finished debugging the attached process, you can use
  759. the `detach' command to release it from GDB's control.  Detaching the
  760. process continues its execution.  After the `detach' command, that
  761. process and GDB become completely independent once more, and you are
  762. ready to `attach' another process or start one with `run'.
  763.  
  764.    If you exit GDB or use the `run' command while you have an attached
  765. process, you kill that process.  You will be asked for confirmation if
  766. you try to do either of these things.
  767.  
  768.    The `attach' command is also used to debug a remote machine via a
  769. serial connection.  *Note Attach::, for more info.
  770.  
  771. File: gdb.info,  Node: Kill Process,  Prev: Attach,  Up: Running
  772.  
  773. Killing the Child Process
  774. =========================
  775.  
  776. `kill'
  777.      Kill the child process in which the program being debugged is
  778.      running under GDB.
  779.  
  780.      This command is useful if you wish to debug a core dump instead.
  781.      GDB ignores any core dump file if it is actually running the
  782.      program, so the `kill' command is the only sure way to make sure
  783.      the core dump file is used once again.
  784.  
  785.      It is also useful if you wish to run the program outside the
  786.      debugger for once and then go back to debugging it.
  787.  
  788.      The `kill' command is also useful if you wish to recompile and
  789.      relink the program, since on many systems it is impossible to
  790.      modify an executable file which is running in a process.  But, in
  791.      this case, it is just as good to exit GDB, since you will need to
  792.      read a new symbol table after the program is recompiled if you
  793.      wish to debug the new version, and restarting GDB is the easiest
  794.      way to do that.
  795.  
  796. File: gdb.info,  Node: Stopping,  Next: Stack,  Prev: Running,  Up: Top
  797.  
  798. Stopping and Continuing
  799. ***********************
  800.  
  801.    When you run a program normally, it runs until it terminates.  The
  802. principal purpose of using a debugger is so that you can stop it before
  803. that point; or so that if the program runs into trouble you can
  804. investigate and find out why.
  805.  
  806. * Menu:
  807.  
  808. * Signals::      Fatal signals in your program just stop it;
  809.                  then you can use GDB to see what is going on.
  810. * Breakpoints::  Breakpoints let you stop your program when it
  811.                  reaches a specified point in the code.
  812. * Continuing::   Resuming execution until the next signal or breakpoint.
  813. * Stepping::     Stepping runs the program a short distance and
  814.                  then stops it wherever it has come to.
  815.  
  816. File: gdb.info,  Node: Signals,  Next: Breakpoints,  Prev: Stopping,  Up: Stopping
  817.  
  818. Signals
  819. =======
  820.  
  821.    A signal is an asynchronous event that can happen in a program.  The
  822. operating system defines the possible kinds of signals, and gives each
  823. kind a name and a number.  For example, `SIGINT' is the signal a program
  824. gets when you type `Ctrl-c'; `SIGSEGV' is the signal a program gets
  825. from referencing a place in memory far away from all the areas in use;
  826. `SIGALRM' occurs when the alarm clock timer goes off (which happens
  827. only if the program has requested an alarm).
  828.  
  829.    Some signals, including `SIGALRM', are a normal part of the
  830. functioning of the program.  Others, such as `SIGSEGV', indicate
  831. errors; these signals are "fatal" (kill the program immediately) if the
  832. program has not specified in advance some other way to handle the
  833. signal.  `SIGINT' does not indicate an error in the program, but it is
  834. normally fatal so it can carry out the purpose of `Ctrl-c': to kill the
  835. program.
  836.  
  837.    GDB has the ability to detect any occurrence of a signal in the
  838. program running under GDB's control.  You can tell GDB in advance what
  839. to do for each kind of signal.
  840.  
  841.    Normally, GDB is set up to ignore non-erroneous signals like
  842. `SIGALRM' (so as not to interfere with their role in the functioning of
  843. the program) but to stop the program immediately whenever an error
  844. signal happens.  You can change these settings with the `handle'
  845. command.  You must specify which signal you are talking about with its
  846. number.
  847.  
  848. `info signal'
  849.      Print a table of all the kinds of signals and how GDB has been
  850.      told to handle each one.  You can use this to see the signal
  851.      numbers of all the defined types of signals.
  852.  
  853. `handle SIGNALNUM KEYWORDS...'
  854.      Change the way GDB handles signal SIGNALNUM.  The KEYWORDS say
  855.      what change to make.
  856.  
  857.    To use the `handle' command you must know the code number of the
  858. signal you are concerned with.  To find the code number, type `info
  859. signal' which prints a table of signal names and numbers.
  860.  
  861.    The keywords allowed by the handle command can be abbreviated.
  862. Their full names are
  863.  
  864. `stop'
  865.      GDB should stop the program when this signal happens.  This implies
  866.      the `print' keyword as well.
  867.  
  868. `print'
  869.      GDB should print a message when this signal happens.
  870.  
  871. `nostop'
  872.      GDB should not stop the program when this signal happens.  It may
  873.      still print a message telling you that the signal has come in.
  874.  
  875. `noprint'
  876.      GDB should not mention the occurrence of the signal at all.  This
  877.      implies the `nostop' keyword as well.
  878.  
  879. `pass'
  880.      GDB should allow the program to see this signal; the program will
  881.      be able to handle the signal, or may be terminated if the signal
  882.      is fatal and not handled.
  883.  
  884. `nopass'
  885.      GDB should not allow the program to see this signal.
  886.  
  887.    When a signal has been set to stop the program, the program cannot
  888. see the signal until you continue.  It will see the signal then, if
  889. `pass' is in effect for the signal in question at that time.  In other
  890. words, after GDB reports a signal, you can use the `handle' command with
  891. `pass' or `nopass' to control whether that signal will be seen by the
  892. program when you later continue it.
  893.  
  894.    You can also use the `signal' command to prevent the program from
  895. seeing a signal, or cause it to see a signal it normally would not see,
  896. or to give it any signal at any time.  *Note Signaling::.
  897.  
  898. File: gdb.info,  Node: Breakpoints,  Next: Continuing,  Prev: Signals,  Up: Stopping
  899.  
  900. Breakpoints
  901. ===========
  902.  
  903.    A "breakpoint" makes your program stop whenever a certain point in
  904. the program is reached.  You set breakpoints explicitly with GDB
  905. commands, specifying the place where the program should stop by line
  906. number, function name or exact address in the program.  You can add
  907. various other conditions to control whether the program will stop.
  908.  
  909.    Each breakpoint is assigned a number when it is created; these
  910. numbers are successive integers starting with 1.  In many of the
  911. commands for controlling various features of breakpoints you use the
  912. breakpoint number to say which breakpoint you want to change.  Each
  913. breakpoint may be "enabled" or "disabled"; if disabled, it has no
  914. effect on the program until you enable it again.
  915.  
  916.    The command `info break' prints a list of all breakpoints set and not
  917. deleted, showing their numbers, where in the program they are, and any
  918. special features in use for them.  Disabled breakpoints are included in
  919. the list, but marked as disabled.  `info break' with a breakpoint number
  920. as argument lists only that breakpoint.  The convenience variable `$_'
  921. and the default examining-address for the `x' command are set to the
  922. address of the last breakpoint listed (*note Memory::.).
  923.  
  924. * Menu:
  925.  
  926. * Set Breaks::     How to establish breakpoints.
  927. * Delete Breaks::   How to remove breakpoints no longer needed.
  928. * Disabling::      How to disable breakpoints (turn them off temporarily).
  929. * Conditions::     Making extra conditions on whether to stop.
  930. * Break Commands:: Commands to be executed at a breakpoint.
  931. * Error in Breakpoints:: "Cannot insert breakpoints" error-why, what to do.
  932.  
  933. File: gdb.info,  Node: Set Breaks,  Next: Delete Breaks,  Prev: Breakpoints,  Up: Breakpoints
  934.  
  935. Setting Breakpoints
  936. -------------------
  937.  
  938.    Breakpoints are set with the `break' command (abbreviated `b').  You
  939. have several ways to say where the breakpoint should go.
  940.  
  941. `break FUNCTION'
  942.      Set a breakpoint at entry to function FUNCTION.
  943.  
  944. `break +OFFSET'
  945. `break -OFFSET'
  946.      Set a breakpoint some number of lines forward or back from the
  947.      position at which execution stopped in the currently selected
  948.      frame.
  949.  
  950. `break LINENUM'
  951.      Set a breakpoint at line LINENUM in the current source file.  That
  952.      file is the last file whose source text was printed.  This
  953.      breakpoint will stop the program just before it executes any of the
  954.      code on that line.
  955.  
  956. `break FILENAME:LINENUM'
  957.      Set a breakpoint at line LINENUM in source file FILENAME.
  958.  
  959. `break FILENAME:FUNCTION'
  960.      Set a breakpoint at entry to function FUNCTION found in file
  961.      FILENAME.  Specifying a file name as well as a function name is
  962.      superfluous except when multiple files contain similarly named
  963.      functions.
  964.  
  965. `break *ADDRESS'
  966.      Set a breakpoint at address ADDRESS.  You can use this to set
  967.      breakpoints in parts of the program which do not have debugging
  968.      information or source files.
  969.  
  970. `break'
  971.      Set a breakpoint at the next instruction to be executed in the
  972.      selected stack frame (*note Stack::.).  In any selected frame but
  973.      the innermost, this will cause the program to stop as soon as
  974.      control returns to that frame.  This is equivalent to a `finish'
  975.      command in the frame inside the selected frame.  If this is done
  976.      in the innermost frame, GDB will stop the next time it reaches the
  977.      current location; this may be useful inside of loops.
  978.  
  979.      GDB normally ignores breakpoints when it resumes execution, until
  980.      at least one instruction has been executed.  If it did not do
  981.      this, you would be unable to proceed past a breakpoint without
  982.      first disabling the breakpoint.  This rule applies whether or not
  983.      the breakpoint already existed when the program stopped.
  984.  
  985. `break ... if COND'
  986.      Set a breakpoint with condition COND; evaluate the expression COND
  987.      each time the breakpoint is reached, and stop only if the value is
  988.      nonzero.  `...' stands for one of the possible arguments described
  989.      above (or no argument) specifying where to break.  *Note
  990.      Conditions::, for more information on breakpoint conditions.
  991.  
  992. `tbreak ARGS'
  993.      Set a breakpoint enabled only for one stop.  ARGS are the same as
  994.      in the `break' command, and the breakpoint is set in the same way,
  995.      but the breakpoint is automatically disabled the first time it is
  996.      hit.  *Note Disabling::.
  997.  
  998.    GDB allows you to set any number of breakpoints at the same place in
  999. the program.  There is nothing silly or meaningless about this.  When
  1000. the breakpoints are conditional, this is even useful (*note
  1001. Conditions::.).
  1002.  
  1003. File: gdb.info,  Node: Delete Breaks,  Next: Disabling,  Prev: Set Breaks,  Up: Breakpoints
  1004.  
  1005. Deleting Breakpoints
  1006. --------------------
  1007.  
  1008.    It is often necessary to eliminate a breakpoint once it has done its
  1009. job and you no longer want the program to stop there.  This is called
  1010. "deleting" the breakpoint.  A breakpoint that has been deleted no
  1011. longer exists in any sense; it is forgotten.
  1012.  
  1013.    With the `clear' command you can delete breakpoints according to
  1014. where they are in the program.  With the `delete' command you can delete
  1015. individual breakpoints by specifying their breakpoint numbers.
  1016.  
  1017.    It is not necessary to delete a breakpoint to proceed past it.  GDB
  1018. automatically ignores breakpoints in the first instruction to be
  1019. executed when you continue execution without changing the execution
  1020. address.
  1021.  
  1022. `clear'
  1023.      Delete any breakpoints at the next instruction to be executed in
  1024.      the selected stack frame (*note Selection::.).  When the innermost
  1025.      frame is selected, this is a good way to delete a breakpoint that
  1026.      the program just stopped at.
  1027.  
  1028. `clear FUNCTION'
  1029. `clear FILENAME:FUNCTION'
  1030.      Delete any breakpoints set at entry to the function FUNCTION.
  1031.  
  1032. `clear LINENUM'
  1033. `clear FILENAME:LINENUM'
  1034.      Delete any breakpoints set at or within the code of the specified
  1035.      line.
  1036.  
  1037. `delete BNUMS...'
  1038.      Delete the breakpoints of the numbers specified as arguments.
  1039.  
  1040. File: gdb.info,  Node: Disabling,  Next: Conditions,  Prev: Delete Breaks,  Up: Breakpoints
  1041.  
  1042. Disabling Breakpoints
  1043. ---------------------
  1044.  
  1045.    Rather than deleting a breakpoint, you might prefer to "disable" it.
  1046. This makes the breakpoint inoperative as if it had been deleted, but
  1047. remembers the information on the breakpoint so that you can "enable" it
  1048. again later.
  1049.  
  1050.    You disable and enable breakpoints with the `enable' and `disable'
  1051. commands, specifying one or more breakpoint numbers as arguments.  Use
  1052. `info break' to print a list of breakpoints if you don't know which
  1053. breakpoint numbers to use.
  1054.  
  1055.    A breakpoint can have any of four different states of enablement:
  1056.  
  1057.    * Enabled.  The breakpoint will stop the program.  A breakpoint made
  1058.      with the `break' command starts out in this state.
  1059.  
  1060.    * Disabled.  The breakpoint has no effect on the program.
  1061.  
  1062.    * Enabled once.  The breakpoint will stop the program, but when it
  1063.      does so it will become disabled.  A breakpoint made with the
  1064.      `tbreak' command starts out in this state.
  1065.  
  1066.    * Enabled for deletion.  The breakpoint will stop the program, but
  1067.      immediately after it does so it will be deleted permanently.
  1068.  
  1069.    You change the state of enablement of a breakpoint with the following
  1070. commands:
  1071.  
  1072. `disable breakpoints BNUMS...'
  1073. `disable BNUMS...'
  1074.      Disable the specified breakpoints.  A disabled breakpoint has no
  1075.      effect but is not forgotten.  All options such as ignore-counts,
  1076.      conditions and commands are remembered in case the breakpoint is
  1077.      enabled again later.
  1078.  
  1079. `enable breakpoints BNUMS...'
  1080. `enable BNUMS...'
  1081.      Enable the specified breakpoints.  They become effective once
  1082.      again in stopping the program, until you specify otherwise.
  1083.  
  1084. `enable breakpoints once BNUMS...'
  1085. `enable once BNUMS...'
  1086.      Enable the specified breakpoints temporarily.  Each will be
  1087.      disabled again the next time it stops the program (unless you have
  1088.      used one of these commands to specify a different state before
  1089.      that time comes).
  1090.  
  1091. `enable breakpoints delete BNUMS...'
  1092. `enable delete BNUMS...'
  1093.      Enable the specified breakpoints to work once and then die.  Each
  1094.      of the breakpoints will be deleted the next time it stops the
  1095.      program (unless you have used one of these commands to specify a
  1096.      different state before that time comes).
  1097.  
  1098.    Aside from the automatic disablement or deletion of a breakpoint
  1099. when it stops the program, which happens only in certain states, the
  1100. state of enablement of a breakpoint changes only when one of the
  1101. commands above is used.
  1102.  
  1103. File: gdb.info,  Node: Conditions,  Next: Break Commands,  Prev: Disabling,  Up: Breakpoints
  1104.  
  1105. Break Conditions
  1106. ----------------
  1107.  
  1108.    The simplest sort of breakpoint breaks every time the program
  1109. reaches a specified place.  You can also specify a "condition" for a
  1110. breakpoint.  A condition is just a boolean expression in your
  1111. programming language.  (*Note Expressions::).  A breakpoint with a
  1112. condition evaluates the expression each time the program reaches it, and
  1113. the program stops only if the condition is true.
  1114.  
  1115.    Break conditions may have side effects, and may even call functions
  1116. in your program.  These may sound like strange things to do, but their
  1117. effects are completely predictable unless there is another enabled
  1118. breakpoint at the same address.  (In that case, GDB might see the other
  1119. breakpoint first and stop the program without checking the condition of
  1120. this one.)  Note that breakpoint commands are usually more convenient
  1121. and flexible for the purpose of performing side effects when a
  1122. breakpoint is reached (*note Break Commands::.).
  1123.  
  1124.    Break conditions can be specified when a breakpoint is set, by using
  1125. `if' in the arguments to the `break' command.  *Note Set Breaks::.
  1126. They can also be changed at any time with the `condition' command:
  1127.  
  1128. `condition BNUM EXPRESSION'
  1129.      Specify EXPRESSION as the break condition for breakpoint number
  1130.      BNUM.  From now on, this breakpoint will stop the program only if
  1131.      the value of EXPRESSION is true (nonzero, in C).  EXPRESSION is
  1132.      not evaluated at the time the `condition' command is given.  *Note
  1133.      Expressions::.
  1134.  
  1135. `condition BNUM'
  1136.      Remove the condition from breakpoint number BNUM.  It becomes an
  1137.      ordinary unconditional breakpoint.
  1138.  
  1139.    A special case of a breakpoint condition is to stop only when the
  1140. breakpoint has been reached a certain number of times.  This is so
  1141. useful that there is a special way to do it, using the "ignore count"
  1142. of the breakpoint.  Every breakpoint has an ignore count, which is an
  1143. integer.  Most of the time, the ignore count is zero, and therefore has
  1144. no effect.  But if the program reaches a breakpoint whose ignore count
  1145. is positive, then instead of stopping, it just decrements the ignore
  1146. count by one and continues.  As a result, if the ignore count value is
  1147. N, the breakpoint will not stop the next N times it is reached.
  1148.  
  1149. `ignore BNUM COUNT'
  1150.      Set the ignore count of breakpoint number BNUM to COUNT.  The next
  1151.      COUNT times the breakpoint is reached, it will not stop.
  1152.  
  1153.      To make the breakpoint stop the next time it is reached, specify a
  1154.      count of zero.
  1155.  
  1156. `cont COUNT'
  1157.      Continue execution of the program, setting the ignore count of the
  1158.      breakpoint that the program stopped at to COUNT minus one.  Thus,
  1159.      the program will not stop at this breakpoint until the COUNT'th
  1160.      time it is reached.
  1161.  
  1162.      This command is allowed only when the program stopped due to a
  1163.      breakpoint.  At other times, the argument to `cont' is ignored.
  1164.  
  1165.    If a breakpoint has a positive ignore count and a condition, the
  1166. condition is not checked.  Once the ignore count reaches zero, the
  1167. condition will start to be checked.
  1168.  
  1169.    Note that you could achieve the effect of the ignore count with a
  1170. condition such as `$foo-- <= 0' using a debugger convenience variable
  1171. that is decremented each time.  *Note Convenience Vars::.
  1172.  
  1173. File: gdb.info,  Node: Break Commands,  Next: Error in Breakpoints,  Prev: Conditions,  Up: Breakpoints
  1174.  
  1175. Commands Executed on Breaking
  1176. -----------------------------
  1177.  
  1178.    You can give any breakpoint a series of commands to execute when the
  1179. program stops due to that breakpoint.  For example, you might want to
  1180. print the values of certain expressions, or enable other breakpoints.
  1181.  
  1182. `commands BNUM'
  1183.      Specify commands for breakpoint number BNUM.  The commands
  1184.      themselves appear on the following lines.  Type a line containing
  1185.      just `end' to terminate the commands.
  1186.  
  1187.      To remove all commands from a breakpoint, use the command
  1188.      `commands' and follow it immediately by `end'; that is, give no
  1189.      commands.
  1190.  
  1191.      With no arguments, `commands' refers to the last breakpoint set.
  1192.  
  1193.    It is possible for breakpoint commands to start the program up again.
  1194. Simply use the `cont' command, or `step', or any other command to
  1195. resume execution.  However, any remaining breakpoint commands are
  1196. ignored.  When the program stops again, GDB will act according to the
  1197. cause of that stop.
  1198.  
  1199.    If the first command specified is `silent', the usual message about
  1200. stopping at a breakpoint is not printed.  This may be desirable for
  1201. breakpoints that are to print a specific message and then continue.  If
  1202. the remaining commands too print nothing, you will see no sign that the
  1203. breakpoint was reached at all.  `silent' is not really a command; it is
  1204. meaningful only at the beginning of the commands for a breakpoint.
  1205.  
  1206.    The commands `echo' and `output' that allow you to print precisely
  1207. controlled output are often useful in silent breakpoints.  *Note
  1208. Output::.
  1209.  
  1210.    For example, here is how you could use breakpoint commands to print
  1211. the value of `x' at entry to `foo' whenever it is positive.
  1212.  
  1213.      break foo if x>0
  1214.      commands
  1215.      silent
  1216.      echo x is\040
  1217.      output x
  1218.      echo \n
  1219.      cont
  1220.      end
  1221.  
  1222.    One application for breakpoint commands is to correct one bug so you
  1223. can test another.  Put a breakpoint just after the erroneous line of
  1224. code, give it a condition to detect the case in which something
  1225. erroneous has been done, and give it commands to assign correct values
  1226. to any variables that need them.  End with the `cont' command so that
  1227. the program does not stop, and start with the `silent' command so that
  1228. no output is produced.  Here is an example:
  1229.  
  1230.      break 403
  1231.      commands
  1232.      silent
  1233.      set x = y + 4
  1234.      cont
  1235.      end
  1236.  
  1237.    One deficiency in the operation of automatically continuing
  1238. breakpoints under Unix appears when your program uses raw mode for the
  1239. terminal.  GDB switches back to its own terminal modes (not raw) before
  1240. executing commands, and then must switch back to raw mode when your
  1241. program is continued.  This causes any pending terminal input to be
  1242. lost.
  1243.  
  1244.    In the GNU system, this will be fixed by changing the behavior of
  1245. terminal modes.
  1246.  
  1247.    Under Unix, when you have this problem, you might be able to get
  1248. around it by putting your actions into the breakpoint condition instead
  1249. of commands.  For example
  1250.  
  1251.      condition 5  (x = y + 4), 0
  1252.  
  1253. specifies a condition expression (*Note Expressions::) that will change
  1254. `x' as needed, then always have the value 0 so the program will not
  1255. stop.  Loss of input is avoided here because break conditions are
  1256. evaluated without changing the terminal modes.  When you want to have
  1257. nontrivial conditions for performing the side effects, the operators
  1258. `&&', `||' and `?...:' may be useful.
  1259.  
  1260. File: gdb.info,  Node: Error in Breakpoints,  Prev: Break Commands,  Up: Breakpoints
  1261.  
  1262. "Cannot Insert Breakpoints" Error
  1263. ---------------------------------
  1264.  
  1265.    Under some operating systems, breakpoints cannot be used in a
  1266. program if any other process is running that program.  Attempting to
  1267. run or continue the program with a breakpoint in this case will cause
  1268. GDB to stop it.
  1269.  
  1270.    When this happens, you have three ways to proceed:
  1271.  
  1272.   1. Remove or disable the breakpoints, then continue.
  1273.  
  1274.   2. Suspend GDB, and copy the file containing the program to a new
  1275.      name.  Resume GDB and use the `exec-file' command to specify that
  1276.      GDB should run the program under that name.  Then start the
  1277.      program again.
  1278.  
  1279.   3. Relink the program so that the text segment is nonsharable, using
  1280.      the linker option `-N'.  The operating system limitation may not
  1281.      apply to nonsharable executables.
  1282.  
  1283. File: gdb.info,  Node: Continuing,  Next: Stepping,  Prev: Breakpoints,  Up: Stopping
  1284.  
  1285. Continuing
  1286. ==========
  1287.  
  1288.    After your program stops, most likely you will want it to run some
  1289. more if the bug you are looking for has not happened yet.
  1290.  
  1291. `cont'
  1292.      Continue running the program at the place where it stopped.
  1293.  
  1294.    If the program stopped at a breakpoint, the place to continue running
  1295. is the address of the breakpoint.  You might expect that continuing
  1296. would just stop at the same breakpoint immediately.  In fact, `cont'
  1297. takes special care to prevent that from happening.  You do not need to
  1298. delete the breakpoint to proceed through it after stopping at it.
  1299.  
  1300.    You can, however, specify an ignore-count for the breakpoint that the
  1301. program stopped at, by means of an argument to the `cont' command.
  1302. *Note Conditions::.
  1303.  
  1304.    If the program stopped because of a signal other than `SIGINT' or
  1305. `SIGTRAP', continuing will cause the program to see that signal.  You
  1306. may not want this to happen.  For example, if the program stopped due
  1307. to some sort of memory reference error, you might store correct values
  1308. into the erroneous variables and continue, hoping to see more
  1309. execution; but the program would probably terminate immediately as a
  1310. result of the fatal signal once it sees the signal.  To prevent this,
  1311. you can continue with `signal 0'.  *Note Signaling::.  You can also act
  1312. in advance to prevent the program from seeing certain kinds of signals,
  1313. using the `handle' command (*note Signals::.).
  1314.  
  1315. File: gdb.info,  Node: Stepping,  Prev: Continuing,  Up: Stopping
  1316.  
  1317. Stepping
  1318. ========
  1319.  
  1320.    "Stepping" means setting your program in motion for a limited time,
  1321. so that control will return automatically to the debugger after one
  1322. line of code or one machine instruction.  Breakpoints are active during
  1323. stepping and the program will stop for them even if it has not gone as
  1324. far as the stepping command specifies.
  1325.  
  1326. `step'
  1327.      Continue running the program until control reaches a different
  1328.      line, then stop it and return control to the debugger.  This
  1329.      command is abbreviated `s'.
  1330.  
  1331.      This command may be given when control is within a function for
  1332.      which there is no debugging information.  In that case, execution
  1333.      will proceed until control reaches a different function, or is
  1334.      about to return from this function.  An argument repeats this
  1335.      action.
  1336.  
  1337. `step COUNT'
  1338.      Continue running as in `step', but do so COUNT times.  If a
  1339.      breakpoint is reached or a signal not related to stepping occurs
  1340.      before COUNT steps, stepping stops right away.
  1341.  
  1342. `next'
  1343.      Similar to `step', but any function calls appearing within the
  1344.      line of code are executed without stopping.  Execution stops when
  1345.      control reaches a different line of code at the stack level which
  1346.      was executing when the `next' command was given.  This command is
  1347.      abbreviated `n'.
  1348.  
  1349.      An argument is a repeat count, as in `step'.
  1350.  
  1351.      `next' within a function without debugging information acts as does
  1352.      `step', but any function calls appearing within the code of the
  1353.      function are executed without stopping.
  1354.  
  1355. `finish'
  1356.      Continue running until just after the selected stack frame returns
  1357.      (or until there is some other reason to stop, such as a fatal
  1358.      signal or a breakpoint).  Print value returned by the selected
  1359.      stack frame (if any).
  1360.  
  1361.      Contrast this with the `return' command (*note Returning::.).
  1362.  
  1363. `until'
  1364.      This command is used to avoid single stepping through a loop more
  1365.      than once.  It is like the `next' command, except that when `until'
  1366.      encounters a jump, it automatically continues execution until the
  1367.      program counter is greater than the address of the jump.
  1368.  
  1369.      This means that when you reach the end of a loop after single
  1370.      stepping though it, `until' will cause the program to continue
  1371.      execution until the loop is exited.  In contrast, a `next' command
  1372.      at the end of a loop will simply step back to the beginning of the
  1373.      loop, which would force you to step through the next iteration.
  1374.  
  1375.      `until' always stops the program if it attempts to exit the current
  1376.      stack frame.
  1377.  
  1378.      `until' may produce somewhat counterintuitive results if the order
  1379.      of the source lines does not match the actual order of execution.
  1380.      For example, in a typical C `for'-loop, the third expression in the
  1381.      `for'-statement (the loop-step expression) is executed after the
  1382.      statements in the body of the loop, but is written before them.
  1383.      Therefore, the `until' command would appear to step back to the
  1384.      beginning of the loop when it advances to this expression.
  1385.      However, it has not really done so, not in terms of the actual
  1386.      machine code.
  1387.  
  1388.      Note that `until' with no argument works by means of single
  1389.      instruction stepping, and hence is slower than `until' with an
  1390.      argument.
  1391.  
  1392. `until LOCATION'
  1393.      Continue running the program until either the specified location is
  1394.      reached, or the current (innermost) stack frame returns.  This
  1395.      form of the command uses breakpoints, and hence is quicker than
  1396.      `until' without an argument.
  1397.  
  1398. `stepi'
  1399. `si'
  1400.      Execute one machine instruction, then stop and return to the
  1401.      debugger.
  1402.  
  1403.      It is often useful to do `display/i $pc' when stepping by machine
  1404.      instructions.  This will cause the next instruction to be executed
  1405.      to be displayed automatically at each stop.  *Note Auto Display::.
  1406.  
  1407.      An argument is a repeat count, as in `step'.
  1408.  
  1409. `nexti'
  1410. `ni'
  1411.      Execute one machine instruction, but if it is a subroutine call,
  1412.      proceed until the subroutine returns.
  1413.  
  1414.      An argument is a repeat count, as in `next'.
  1415.  
  1416.    A typical technique for using stepping is to put a breakpoint (*note
  1417. Breakpoints::.) at the beginning of the function or the section of the
  1418. program in which a problem is believed to lie, and then step through
  1419. the suspect area, examining the variables that are interesting, until
  1420. the problem happens.
  1421.  
  1422.    The `cont' command can be used after stepping to resume execution
  1423. until the next breakpoint or signal.
  1424.  
  1425. File: gdb.info,  Node: Stack,  Next: Source,  Prev: Stopping,  Up: Top
  1426.  
  1427. Examining the Stack
  1428. *******************
  1429.  
  1430.    When your program has stopped, the first thing you need to know is
  1431. where it stopped and how it got there.
  1432.  
  1433.    Each time your program performs a function call, the information
  1434. about where in the program the call was made from is saved in a block
  1435. of data called a "stack frame".  The frame also contains the arguments
  1436. of the call and the local variables of the function that was called.
  1437. All the stack frames are allocated in a region of memory called the
  1438. "call stack".
  1439.  
  1440.    When your program stops, the GDB commands for examining the stack
  1441. allow you to see all of this information.
  1442.  
  1443.    One of the stack frames is "selected" by GDB and many GDB commands
  1444. refer implicitly to the selected frame.  In particular, whenever you ask
  1445. GDB for the value of a variable in the program, the value is found in
  1446. the selected frame.  There are special GDB commands to select whichever
  1447. frame you are interested in.
  1448.  
  1449.    When the program stops, GDB automatically selects the currently
  1450. executing frame and describes it briefly as the `frame' command does
  1451. (*note Info: Frame Info.).
  1452.  
  1453. * Menu:
  1454.  
  1455. * Frames::          Explanation of stack frames and terminology.
  1456. * Backtrace::       Summarizing many frames at once.
  1457. * Selection::       How to select a stack frame.
  1458. * Info: Frame Info, Commands to print information on stack frames.
  1459.  
  1460. File: gdb.info,  Node: Frames,  Next: Backtrace,  Prev: Stack,  Up: Stack
  1461.  
  1462. Stack Frames
  1463. ============
  1464.  
  1465.    The call stack is divided up into contiguous pieces called "stack
  1466. frames", or "frames" for short; each frame is the data associated with
  1467. one call to one function.  The frame contains the arguments given to
  1468. the function, the function's local variables, and the address at which
  1469. the function is executing.
  1470.  
  1471.    When your program is started, the stack has only one frame, that of
  1472. the function `main'.  This is called the "initial" frame or the
  1473. "outermost" frame.  Each time a function is called, a new frame is
  1474. made.  Each time a function returns, the frame for that function
  1475. invocation is eliminated.  If a function is recursive, there can be
  1476. many frames for the same function.  The frame for the function in which
  1477. execution is actually occurring is called the "innermost" frame.  This
  1478. is the most recently created of all the stack frames that still exist.
  1479.  
  1480.    Inside your program, stack frames are identified by their addresses.
  1481. A stack frame consists of many bytes, each of which has its own
  1482. address; each kind of computer has a convention for choosing one of
  1483. those bytes whose address serves as the address of the frame.  Usually
  1484. this address is kept in a register called the "frame pointer register"
  1485. while execution is going on in that frame.
  1486.  
  1487.    GDB assigns numbers to all existing stack frames, starting with zero
  1488. for the innermost frame, one for the frame that called it, and so on
  1489. upward.  These numbers do not really exist in your program; they are to
  1490. give you a way of talking about stack frames in GDB commands.
  1491.  
  1492.    Many GDB commands refer implicitly to one stack frame.  GDB records
  1493. a stack frame that is called the "selected" stack frame; you can select
  1494. any frame using one set of GDB commands, and then other commands will
  1495. operate on that frame.  When your program stops, GDB automatically
  1496. selects the innermost frame.
  1497.  
  1498.    Some functions can be compiled to run without a frame reserved for
  1499. them on the stack.  This is occasionally done with heavily used library
  1500. functions to save the frame setup time.  GDB has limited facilities for
  1501. dealing with these function invocations; if the innermost function
  1502. invocation has no stack frame, GDB will give it a virtual stack frame of
  1503. 0 and correctly allow tracing of the function call chain.  Results are
  1504. undefined if a function invocation besides the innermost one is
  1505. frameless.
  1506.  
  1507. File: gdb.info,  Node: Backtrace,  Next: Selection,  Prev: Frames,  Up: Stack
  1508.  
  1509. Backtraces
  1510. ==========
  1511.  
  1512.    A backtrace is a summary of how the program got where it is.  It
  1513. shows one line per frame, for many frames, starting with the currently
  1514. executing frame (frame zero), followed by its caller (frame one), and
  1515. on up the stack.
  1516.  
  1517. `backtrace'
  1518. `bt'
  1519.      Print a backtrace of the entire stack: one line per frame for all
  1520.      frames in the stack.
  1521.  
  1522.      You can stop the backtrace at any time by typing the system
  1523.      interrupt character, normally `Control-C'.
  1524.  
  1525. `backtrace N'
  1526. `bt N'
  1527.      Similar, but print only the innermost N frames.
  1528.  
  1529. `backtrace -N'
  1530. `bt -N'
  1531.      Similar, but print only the outermost N frames.
  1532.  
  1533.    The names `where' and `info stack' are additional aliases for
  1534. `backtrace'.
  1535.  
  1536.    Every line in the backtrace shows the frame number, the function name
  1537. and the program counter value.
  1538.  
  1539.    If the function is in a source file whose symbol table data has been
  1540. fully read, the backtrace shows the source file name and line number, as
  1541. well as the arguments to the function.  (The program counter value is
  1542. omitted if it is at the beginning of the code for that line number.)
  1543.  
  1544.    If the source file's symbol data has not been fully read, just
  1545. scanned, this extra information is replaced with an ellipsis.  You can
  1546. force the symbol data for that frame's source file to be read by
  1547. selecting the frame.  (*Note Selection::).
  1548.  
  1549.    Here is an example of a backtrace.  It was made with the command `bt
  1550. 3', so it shows the innermost three frames.
  1551.  
  1552.      #0  rtx_equal_p (x=(rtx) 0x8e58c, y=(rtx) 0x1086c4) (/gp/rms/cc/rtlanal.c line 337)
  1553.      #1  0x246b0 in expand_call (...) (...)
  1554.      #2  0x21cfc in expand_expr (...) (...)
  1555.      (More stack frames follow...)
  1556.  
  1557. The functions `expand_call' and `expand_expr' are in a file whose
  1558. symbol details have not been fully read.  Full detail is available for
  1559. the function `rtx_equal_p', which is in the file `rtlanal.c'.  Its
  1560. arguments, named `x' and `y', are shown with their typed values.
  1561.  
  1562. File: gdb.info,  Node: Selection,  Next: Frame Info,  Prev: Backtrace,  Up: Stack
  1563.  
  1564. Selecting a Frame
  1565. =================
  1566.  
  1567.    Most commands for examining the stack and other data in the program
  1568. work on whichever stack frame is selected at the moment.  Here are the
  1569. commands for selecting a stack frame; all of them finish by printing a
  1570. brief description of the stack frame just selected.
  1571.  
  1572. `frame N'
  1573.      Select frame number N.  Recall that frame zero is the innermost
  1574.      (currently executing) frame, frame one is the frame that called the
  1575.      innermost one, and so on.  The highest-numbered frame is `main''s
  1576.      frame.
  1577.  
  1578. `frame ADDR'
  1579.      Select the frame at address ADDR.  This is useful mainly if the
  1580.      chaining of stack frames has been damaged by a bug, making it
  1581.      impossible for GDB to assign numbers properly to all frames.  In
  1582.      addition, this can be useful when the program has multiple stacks
  1583.      and switches between them.
  1584.  
  1585. `up N'
  1586.      Select the frame N frames up from the frame previously selected.
  1587.      For positive numbers N, this advances toward the outermost frame,
  1588.      to higher frame numbers, to frames that have existed longer.  N
  1589.      defaults to one.
  1590.  
  1591. `down N'
  1592.      Select the frame N frames down from the frame previously selected.
  1593.      For positive numbers N, this advances toward the innermost frame,
  1594.      to lower frame numbers, to frames that were created more recently.
  1595.      N defaults to one.
  1596.  
  1597.    All of these commands end by printing some information on the frame
  1598. that has been selected: the frame number, the function name, the
  1599. arguments, the source file and line number of execution in that frame,
  1600. and the text of that source line.  For example:
  1601.  
  1602.      #3  main (argc=3, argv=??, env=??) at main.c, line 67
  1603.      67        read_input_file (argv[i]);
  1604.  
  1605.    After such a printout, the `list' command with no arguments will
  1606. print ten lines centered on the point of execution in the frame.  *Note
  1607. List::.
  1608.  
  1609. File: gdb.info,  Node: Frame Info,  Prev: Selection,  Up: Stack
  1610.  
  1611. Information on a Frame
  1612. ======================
  1613.  
  1614.    There are several other commands to print information about the
  1615. selected stack frame.
  1616.  
  1617. `frame'
  1618.      This command prints a brief description of the selected stack
  1619.      frame.  It can be abbreviated `f'.  With an argument, this command
  1620.      is used to select a stack frame; with no argument, it does not
  1621.      change which frame is selected, but still prints the same
  1622.      information.
  1623.  
  1624. `info frame'
  1625.      This command prints a verbose description of the selected stack
  1626.      frame, including the address of the frame, the addresses of the
  1627.      next frame in (called by this frame) and the next frame out
  1628.      (caller of this frame), the address of the frame's arguments, the
  1629.      program counter saved in it (the address of execution in the
  1630.      caller frame), and which registers were saved in the frame.  The
  1631.      verbose description is useful when something has gone wrong that
  1632.      has made the stack format fail to fit the usual conventions.
  1633.  
  1634. `info frame ADDR'
  1635.      Print a verbose description of the frame at address ADDR, without
  1636.      selecting that frame.  The selected frame remains unchanged by
  1637.      this command.
  1638.  
  1639. `info args'
  1640.      Print the arguments of the selected frame, each on a separate line.
  1641.  
  1642. `info locals'
  1643.      Print the local variables of the selected frame, each on a separate
  1644.      line.  These are all variables declared static or automatic within
  1645.      all program blocks that execution in this frame is currently
  1646.      inside of.
  1647.  
  1648. File: gdb.info,  Node: Source,  Next: Data,  Prev: Stack,  Up: Top
  1649.  
  1650. Examining Source Files
  1651. **********************
  1652.  
  1653.    GDB knows which source files your program was compiled from, and can
  1654. print parts of their text.  When your program stops, GDB spontaneously
  1655. prints the line it stopped in.  Likewise, when you select a stack frame
  1656. (*note Selection::.), GDB prints the line which execution in that frame
  1657. has stopped in.  You can also print parts of source files by explicit
  1658. command.
  1659.  
  1660. * Menu:
  1661.  
  1662. * List::        Using the `list' command to print source files.
  1663. * Search::      Commands for searching source files.
  1664. * Source Path:: Specifying the directories to search for source files.
  1665.  
  1666. File: gdb.info,  Node: List,  Next: Search,  Prev: Source,  Up: Source
  1667.  
  1668. Printing Source Lines
  1669. =====================
  1670.  
  1671.    To print lines from a source file, use the `list' command
  1672. (abbreviated `l').  There are several ways to specify what part of the
  1673. file you want to print.
  1674.  
  1675.    Here are the forms of the `list' command most commonly used:
  1676.  
  1677. `list LINENUM'
  1678.      Print ten lines centered around line number LINENUM in the current
  1679.      source file.
  1680.  
  1681. `list FUNCTION'
  1682.      Print ten lines centered around the beginning of function FUNCTION.
  1683.  
  1684. `list'
  1685.      Print ten more lines.  If the last lines printed were printed with
  1686.      a `list' command, this prints ten lines following the last lines
  1687.      printed; however, if the last line printed was a solitary line
  1688.      printed as part of displaying a stack frame (*note Stack::.), this
  1689.      prints ten lines centered around that line.
  1690.  
  1691. `list -'
  1692.      Print ten lines just before the lines last printed.
  1693.  
  1694.    Repeating a `list' command with RET discards the argument, so it is
  1695. equivalent to typing just `list'.  This is more useful than listing the
  1696. same lines again.  An exception is made for an argument of `-'; that
  1697. argument is preserved in repetition so that each repetition moves up in
  1698. the file.
  1699.  
  1700.    In general, the `list' command expects you to supply zero, one or two
  1701. "linespecs".  Linespecs specify source lines; there are several ways of
  1702. writing them but the effect is always to specify some source line.
  1703. Here is a complete description of the possible arguments for `list':
  1704.  
  1705. `list LINESPEC'
  1706.      Print ten lines centered around the line specified by LINESPEC.
  1707.  
  1708. `list FIRST,LAST'
  1709.      Print lines from FIRST to LAST.  Both arguments are linespecs.
  1710.  
  1711. `list ,LAST'
  1712.      Print ten lines ending with LAST.
  1713.  
  1714. `list FIRST,'
  1715.      Print ten lines starting with FIRST.
  1716.  
  1717. `list +'
  1718.      Print ten lines just after the lines last printed.
  1719.  
  1720. `list -'
  1721.      Print ten lines just before the lines last printed.
  1722.  
  1723. `list'
  1724.      As described in the preceding table.
  1725.  
  1726.    Here are the ways of specifying a single source line--all the kinds
  1727. of linespec.
  1728.  
  1729. `LINENUM'
  1730.      Specifies line LINENUM of the current source file.  When a `list'
  1731.      command has two linespecs, this refers to the same source file as
  1732.      the first linespec.
  1733.  
  1734. `+OFFSET'
  1735.      Specifies the line OFFSET lines after the last line printed.  When
  1736.      used as the second linespec in a `list' command that has two, this
  1737.      specifies the line OFFSET lines down from the first linespec.
  1738.  
  1739. `-OFFSET'
  1740.      Specifies the line OFFSET lines before the last line printed.
  1741.  
  1742. `FILENAME:LINENUM'
  1743.      Specifies line LINENUM in the source file FILENAME.
  1744.  
  1745. `FUNCTION'
  1746.      Specifies the line of the open-brace that begins the body of the
  1747.      function FUNCTION.
  1748.  
  1749. `FILENAME:FUNCTION'
  1750.      Specifies the line of the open-brace that begins the body of the
  1751.      function FUNCTION in the file FILENAME.  The file name is needed
  1752.      with a function name only for disambiguation of identically named
  1753.      functions in different source files.
  1754.  
  1755. `*ADDRESS'
  1756.      Specifies the line containing the program address ADDRESS.
  1757.      ADDRESS may be any expression.
  1758.  
  1759.    One other command is used to map source lines to program addresses.
  1760.  
  1761. `info line LINENUM'
  1762.      Print the starting and ending addresses of the compiled code for
  1763.      source line LINENUM.
  1764.  
  1765.      The default examine address for the `x' command is changed to the
  1766.      starting address of the line, so that `x/i' is sufficient to begin
  1767.      examining the machine code (*note Memory::.).  Also, this address
  1768.      is saved as the value of the convenience variable `$_' (*note
  1769.      Convenience Vars::.).
  1770.  
  1771. File: gdb.info,  Node: Search,  Next: Source Path,  Prev: List,  Up: Source
  1772.  
  1773. Searching Source Files
  1774. ======================
  1775.  
  1776.    There are two commands for searching through the current source file
  1777. for a regular expression.
  1778.  
  1779.    The command `forward-search REGEXP' checks each line, starting with
  1780. the one following the last line listed, for a match for REGEXP.  It
  1781. lists the line that is found.  You can abbreviate the command name as
  1782. `fo'.
  1783.  
  1784.    The command `reverse-search REGEXP' checks each line, starting with
  1785. the one before the last line listed and going backward, for a match for
  1786. REGEXP.  It lists the line that is found.  You can abbreviate this
  1787. command with as little as `rev'.
  1788.  
  1789. File: gdb.info,  Node: Source Path,  Prev: Search,  Up: Source
  1790.  
  1791. Specifying Source Directories
  1792. =============================
  1793.  
  1794.    Executable programs do not record the directories of the source files
  1795. from which they were compiled, just the names.  GDB remembers a list of
  1796. directories to search for source files; this is called the "source
  1797. path".  Each time GDB wants a source file, it tries all the directories
  1798. in the list, in the order they are present in the list, until it finds a
  1799. file with the desired name.  Note that the executable search path is
  1800. not used for this purpose.  Neither is the current working directory,
  1801. unless it happens to be in the source path.
  1802.  
  1803.    When you start GDB, its source path contains just the current working
  1804. directory.  To add other directories, use the `directory' command.
  1805.  
  1806. `directory DIRNAMES...'
  1807.      Add directory DIRNAME to the end of the source path.  Several
  1808.      directory names may be given to this command, separated by
  1809.      whitespace or `:'.
  1810.  
  1811. `directory'
  1812.      Reset the source path to just the current working directory of GDB.
  1813.      This requires confirmation.
  1814.  
  1815.      Since this command deletes directories from the search path, it may
  1816.      change the directory in which a previously read source file will be
  1817.      discovered.  To make this work correctly, this command also clears
  1818.      out the tables GDB maintains about the source files it has already
  1819.      found.
  1820.  
  1821. `info directories'
  1822.      Print the source path: show which directories it contains.
  1823.  
  1824.    Because the `directory' command adds to the end of the source path,
  1825. it does not affect any file that GDB has already found.  If the source
  1826. path contains directories that you do not want, and these directories
  1827. contain misleading files with names matching your source files, the way
  1828. to correct the situation is as follows:
  1829.  
  1830.   1. Choose the directory you want at the beginning of the source path.
  1831.      Use the `cd' command to make that the current working directory.
  1832.  
  1833.   2. Use `directory' with no argument to reset the source path to just
  1834.      that directory.
  1835.  
  1836.   3. Use `directory' with suitable arguments to add any other
  1837.      directories you want in the source path.
  1838.  
  1839. File: gdb.info,  Node: Data,  Next: Symbols,  Prev: Source,  Up: Top
  1840.  
  1841. Examining Data
  1842. **************
  1843.  
  1844.    The usual way to examine data in your program is with the `print'
  1845. command (abbreviated `p').  It evaluates and prints the value of any
  1846. valid expression of the language the program is written in (for now, C).
  1847. You type
  1848.  
  1849.      print EXP
  1850.  
  1851. where EXP is any valid expression, and the value of EXP is printed in a
  1852. format appropriate to its data type.
  1853.  
  1854.    A more low-level way of examining data is with the `x' command.  It
  1855. examines data in memory at a specified address and prints it in a
  1856. specified format.
  1857.  
  1858. * Menu:
  1859.  
  1860. * Expressions::      Expressions that can be computed and printed.
  1861. * Variables::        Using your program's variables in expressions.
  1862. * Assignment::       Setting your program's variables.
  1863. * Arrays::           Examining part of memory as an array.
  1864. * Format options::   Controlling how structures and arrays are printed.
  1865. * Output formats::   Specifying formats for printing values.
  1866. * Memory::           Examining memory explicitly.
  1867. * Auto Display::     Printing certain expressions whenever program stops.
  1868. * Value History::    Referring to values previously printed.
  1869. * Convenience Vars:: Giving names to values for future reference.
  1870. * Registers::        Referring to and storing in machine registers.
  1871.  
  1872. File: gdb.info,  Node: Expressions,  Next: Variables,  Prev: Data,  Up: Data
  1873.  
  1874. Expressions
  1875. ===========
  1876.  
  1877.    Many different GDB commands accept an expression and compute its
  1878. value.  Any kind of constant, variable or operator defined by the
  1879. programming language you are using is legal in an expression in GDB.
  1880. This includes conditional expressions, function calls, casts and string
  1881. constants.  It unfortunately does not include symbols defined by
  1882. preprocessor `#define' commands.
  1883.  
  1884.    Casts are supported in all languages, not just in C, because it is so
  1885. useful to cast a number into a pointer so as to examine a structure at
  1886. that address in memory.
  1887.  
  1888.    GDB supports three kinds of operator in addition to those of
  1889. programming languages:
  1890.  
  1891. `@'
  1892.      `@' is a binary operator for treating parts of memory as arrays.
  1893.      *Note Arrays::, for more information.
  1894.  
  1895. `::'
  1896.      `::' allows you to specify a variable in terms of the file or
  1897.      function it is defined in.  *Note Variables::.
  1898.  
  1899. `{TYPE} ADDR'
  1900.      Refers to an object of type TYPE stored at address ADDR in memory.
  1901.      ADDR may be any expression whose value is an integer or pointer
  1902.      (but parentheses are required around nonunary operators, just as in
  1903.      a cast).  This construct is allowed regardless of what kind of
  1904.      data is officially supposed to reside at ADDR.
  1905.  
  1906. File: gdb.info,  Node: Variables,  Next: Arrays,  Prev: Expressions,  Up: Data
  1907.  
  1908. Program Variables
  1909. =================
  1910.  
  1911.    The most common kind of expression to use is the name of a variable
  1912. in your program.
  1913.  
  1914.    Variables in expressions are understood in the selected stack frame
  1915. (*note Selection::.); they must either be global (or static) or be
  1916. visible according to the scope rules of the programming language from
  1917. the point of execution in that frame.  This means that in the function
  1918.  
  1919.      foo (a)
  1920.           int a;
  1921.      {
  1922.        bar (a);
  1923.        {
  1924.          int b = test ();
  1925.          bar (b);
  1926.        }
  1927.      }
  1928.  
  1929. the variable `a' is usable whenever the program is executing within the
  1930. function `foo', but the variable `b' is visible only while the program
  1931. is executing inside the block in which `b' is declared.
  1932.  
  1933.    As a special exception, you can refer to a variable or function whose
  1934. scope is a single source file even if the current execution point is not
  1935. in this file.  But it is possible to have more than one such variable
  1936. or function with the same name (if they are in different source files).
  1937. In such a case, it is not defined which one you will get.  If you wish,
  1938. you can specify any one of them using the colon-colon construct:
  1939.  
  1940.      BLOCK::VARIABLE
  1941.  
  1942. Here BLOCK is the name of the source file whose variable you want.
  1943.  
  1944. File: gdb.info,  Node: Arrays,  Next: Format options,  Prev: Variables,  Up: Data
  1945.  
  1946. Artificial Arrays
  1947. =================
  1948.  
  1949.    It is often useful to print out several successive objects of the
  1950. same type in memory; a section of an array, or an array of dynamically
  1951. determined size for which only a pointer exists in the program.
  1952.  
  1953.    This can be done by constructing an "artificial array" with the
  1954. binary operator `@'.  The left operand of `@' should be the first
  1955. element of the desired array, as an individual object.  The right
  1956. operand should be the length of the array.  The result is an array
  1957. value whose elements are all of the type of the left argument.  The
  1958. first element is actually the left argument; the second element comes
  1959. from bytes of memory immediately following those that hold the first
  1960. element, and so on.  Here is an example.  If a program says
  1961.  
  1962.      int *array = (int *) malloc (len * sizeof (int));
  1963.  
  1964. you can print the contents of `array' with
  1965.  
  1966.      p *array@len
  1967.  
  1968.    The left operand of `@' must reside in memory.  Array values made
  1969. with `@' in this way behave just like other arrays in terms of
  1970. subscripting, and are coerced to pointers when used in expressions.
  1971. (It would probably appear in an expression via the value history, after
  1972. you had printed it out.)
  1973.  
  1974. File: gdb.info,  Node: Format options,  Next: Output formats,  Prev: Arrays,  Up: Data
  1975.  
  1976. Format options
  1977. ==============
  1978.  
  1979.    GDB provides a few ways to control how arrays and structures are
  1980. printed.
  1981.  
  1982. `info format'
  1983.      Display the current settings for the format options.
  1984.  
  1985. `set array-max NUMBER-OF-ELEMENTS'
  1986.      If GDB is printing a large array, it will stop printing after it
  1987.      has printed the number of elements set by the `set array-max'
  1988.      command.  This limit also applies to the display of strings.
  1989.  
  1990. `set prettyprint on'
  1991.      Cause GDB to print structures in an indented format with one
  1992.      member per line, like this:
  1993.  
  1994.           $1 = {
  1995.             next = 0x0,
  1996.             flags = {
  1997.               sweet = 1,
  1998.               sour = 1
  1999.             },
  2000.             meat = 0x54 "Pork"
  2001.           }
  2002.  
  2003. `set prettyprint off'
  2004.      Cause GDB to print structures in a compact format, like this:
  2005.  
  2006.           $1 = {next = 0x0, flags = {sweet = 1, sour = 1}, meat = 0x54 "Pork"}
  2007.  
  2008.      This is the default format.
  2009.  
  2010. `set unionprint on'
  2011.      Tell GDB to print unions which are contained in structures.  This
  2012.      is the default setting.
  2013.  
  2014. `set unionprint off'
  2015.      Tell GDB not to print unions which are contained in structures.
  2016.  
  2017.      For example, given the declarations
  2018.  
  2019.           typedef enum {Tree, Bug} Species;
  2020.           typedef enum {Big_tree, Acorn, Seedling} Tree_forms;
  2021.           typedef enum {Caterpiller, Cocoon, Butterfly} Bug_forms;
  2022.           
  2023.           struct thing {
  2024.             Species it;
  2025.             union {
  2026.               Tree_forms tree;
  2027.               Bug_forms bug;
  2028.             } form;
  2029.           };
  2030.           
  2031.           struct thing foo = {Tree, {Acorn}};
  2032.  
  2033.      with `set unionprint on' in effect `p foo' would print
  2034.  
  2035.           $1 = {it = Tree, form = {tree = Acorn, bug = Cocoon}}
  2036.  
  2037.      and with `set unionprint off' in effect it would print
  2038.  
  2039.           $1 = {it = Tree, form = {...}}
  2040.  
  2041. File: gdb.info,  Node: Output formats,  Next: Memory,  Prev: Format options,  Up: Data
  2042.  
  2043. Output formats
  2044. ==============
  2045.  
  2046.    GDB normally prints all values according to their data types.
  2047. Sometimes this is not what you want.  For example, you might want to
  2048. print a number in hex, or a pointer in decimal.  Or you might want to
  2049. view data in memory at a certain address as a character string or an
  2050. instruction.  These things can be done with "output formats".
  2051.  
  2052.    The simplest use of output formats is to say how to print a value
  2053. already computed.  This is done by starting the arguments of the
  2054. `print' command with a slash and a format letter.  The format letters
  2055. supported are:
  2056.  
  2057. `x'
  2058.      Regard the bits of the value as an integer, and print the integer
  2059.      in hexadecimal.
  2060.  
  2061. `d'
  2062.      Print as integer in signed decimal.
  2063.  
  2064. `u'
  2065.      Print as integer in unsigned decimal.
  2066.  
  2067. `o'
  2068.      Print as integer in octal.
  2069.  
  2070. `a'
  2071.      Print as an address, both absolute in hex and then relative to a
  2072.      symbol defined as an address below it.
  2073.  
  2074. `c'
  2075.      Regard as an integer and print it as a character constant.
  2076.  
  2077. `f'
  2078.      Regard the bits of the value as a floating point number and print
  2079.      using typical floating point syntax.
  2080.  
  2081.    For example, to print the program counter in hex (*note
  2082. Registers::.), type
  2083.  
  2084.      p/x $pc
  2085.  
  2086. Note that no space is required before the slash; this is because command
  2087. names in GDB cannot contain a slash.
  2088.  
  2089.    To reprint the last value in the value history with a different
  2090. format, you can use the `print' command with just a format and no
  2091. expression.  For example, `p/x' reprints the last value in hex.
  2092.  
  2093. File: gdb.info,  Node: Memory,  Next: Auto Display,  Prev: Output formats,  Up: Data
  2094.  
  2095. Examining Memory
  2096. ----------------
  2097.  
  2098.    The command `x' (for `examine') can be used to examine memory
  2099. without reference to the program's data types.  The format in which you
  2100. wish to examine memory is instead explicitly specified.  The allowable
  2101. formats are a superset of the formats described in the previous section.
  2102.  
  2103.    `x' is followed by a slash and an output format specification,
  2104. followed by an expression for an address.  The expression need not have
  2105. a pointer value (though it may); it is used as an integer, as the
  2106. address of a byte of memory.  *Note Expressions:: for more information
  2107. on expressions.  For example, `x/4xw $sp' prints the four words of
  2108. memory above the stack pointer in hexadecimal.
  2109.  
  2110.    The output format in this case specifies both how big a unit of
  2111. memory to examine and how to print the contents of that unit.  It is
  2112. done with one or two of the following letters:
  2113.  
  2114.    These letters specify just the size of unit to examine:
  2115.  
  2116. `b'
  2117.      Examine individual bytes.
  2118.  
  2119. `h'
  2120.      Examine halfwords (two bytes each).
  2121.  
  2122. `w'
  2123.      Examine words (four bytes each).
  2124.  
  2125.      Many assemblers and cpu designers still use `word' for a 16-bit
  2126.      quantity, as a holdover from specific predecessor machines of the
  2127.      1970's that really did use two-byte words.  But more generally the
  2128.      term `word' has always referred to the size of quantity that a
  2129.      machine normally operates on and stores in its registers.  This is
  2130.      32 bits for all the machines that GDB runs on.
  2131.  
  2132. `g'
  2133.      Examine giant words (8 bytes).
  2134.  
  2135.    These letters specify just the way to print the contents:
  2136.  
  2137. `x'
  2138.      Print as integers in unsigned hexadecimal.
  2139.  
  2140. `d'
  2141.      Print as integers in signed decimal.
  2142.  
  2143. `u'
  2144.      Print as integers in unsigned decimal.
  2145.  
  2146. `o'
  2147.      Print as integers in unsigned octal.
  2148.  
  2149. `a'
  2150.      Print as an address, both absolute in hex and then relative to a
  2151.      symbol defined as an address below it.
  2152.  
  2153. `c'
  2154.      Print as character constants.
  2155.  
  2156. `f'
  2157.      Print as floating point.  This works only with sizes `w' and `g'.
  2158.  
  2159. `s'
  2160.      Print a null-terminated string of characters.  The specified unit
  2161.      size is ignored; instead, the unit is however many bytes it takes
  2162.      to reach a null character (including the null character).
  2163.  
  2164. `i'
  2165.      Print a machine instruction in assembler syntax (or nearly).  The
  2166.      specified unit size is ignored; the number of bytes in an
  2167.      instruction varies depending on the type of machine, the opcode
  2168.      and the addressing modes used.
  2169.  
  2170.    If either the manner of printing or the size of unit fails to be
  2171. specified, the default is to use the same one that was used last.  If
  2172. you don't want to use any letters after the slash, you can omit the
  2173. slash as well.
  2174.  
  2175.    You can also omit the address to examine.  Then the address used is
  2176. just after the last unit examined.  This is why string and instruction
  2177. formats actually compute a unit-size based on the data: so that the
  2178. next string or instruction examined will start in the right place.  The
  2179. `print' command sometimes sets the default address for the `x' command;
  2180. when the value printed resides in memory, the default is set to examine
  2181. the same location.  `info line' also sets the default for `x', to the
  2182. address of the start of the machine code for the specified line and
  2183. `info breakpoints' sets it to the address of the last breakpoint listed.
  2184.  
  2185.    When you use RET to repeat an `x' command, it does not repeat
  2186. exactly the same: the address specified previously (if any) is ignored,
  2187. so that the repeated command examines the successive locations in memory
  2188. rather than the same ones.
  2189.  
  2190.    You can examine several consecutive units of memory with one command
  2191. by writing a repeat-count after the slash (before the format letters,
  2192. if any).  The repeat count must be a decimal integer.  It has the same
  2193. effect as repeating the `x' command that many times except that the
  2194. output may be more compact with several units per line.  For example,
  2195.  
  2196.      x/10i $pc
  2197.  
  2198. prints ten instructions starting with the one to be executed next in the
  2199. selected frame.  After doing this, you could print another ten following
  2200. instructions with
  2201.  
  2202.      x/10
  2203.  
  2204. in which the format and address are allowed to default.
  2205.  
  2206.    The addresses and contents printed by the `x' command are not put in
  2207. the value history because there is often too much of them and they would
  2208. get in the way.  Instead, GDB makes these values available for
  2209. subsequent use in expressions as values of the convenience variables
  2210. `$_' and `$__'.
  2211.  
  2212.    After an `x' command, the last address examined is available for use
  2213. in expressions in the convenience variable `$_'.  The contents of that
  2214. address, as examined, are available in the convenience variable `$__'.
  2215.  
  2216.    If the `x' command has a repeat count, the address and contents saved
  2217. are from the last memory unit printed; this is not the same as the last
  2218. address printed if several units were printed on the last line of
  2219. output.
  2220.  
  2221.    The specialized command `disassemble' is also provided to dump a
  2222. range of memory as machine instructions.  The default memory range is
  2223. the function surrounding the program counter of the selected frame.  A
  2224. single argument to this command is a program counter value; the function
  2225. surrounding this value will be dumped.  Two arguments specify a range of
  2226. addresss (first inclusive, second exclusive) to be dumped.
  2227.  
  2228. File: gdb.info,  Node: Auto Display,  Next: Value History,  Prev: Memory,  Up: Data
  2229.  
  2230. Automatic Display
  2231. =================
  2232.  
  2233.    If you find that you want to print the value of an expression
  2234. frequently (to see how it changes), you might want to add it to the
  2235. "automatic display list" so that GDB will print its value each time the
  2236. program stops.  Each expression added to the list is given a number to
  2237. identify it; to remove an expression from the list, you specify that
  2238. number.  The automatic display looks like this:
  2239.  
  2240.      2: foo = 38
  2241.      3: bar[5] = (struct hack *) 0x3804
  2242.  
  2243. showing item numbers, expressions and their current values.
  2244.  
  2245.    If the expression refers to local variables, then it does not make
  2246. sense outside the lexical context for which it was set up.  Such an
  2247. expression is printed only when execution is inside that lexical
  2248. context.  For example, if you give the command `display name' while
  2249. inside a function with an argument `name', then this argument will be
  2250. displayed whenever the program stops inside that function, but not when
  2251. it stops elsewhere (since this argument doesn't exist elsewhere).
  2252.  
  2253. `display EXP'
  2254.      Add the expression EXP to the list of expressions to display each
  2255.      time the program stops.  *Note Expressions::.
  2256.  
  2257. `display/FMT EXP'
  2258.      For FMT specifying only a display format and not a size or count,
  2259.      add the expression EXP to the auto-display list but arranges to
  2260.      display it each time in the specified format FMT.
  2261.  
  2262. `display/FMT ADDR'
  2263.      For FMT `i' or `s', or including a unit-size or a number of units,
  2264.      add the expression ADDR as a memory address to be examined each
  2265.      time the program stops.  Examining means in effect doing `x/FMT
  2266.      ADDR'.  *Note Memory::.
  2267.  
  2268. `undisplay DNUMS...'
  2269. `delete display DNUMS...'
  2270.      Remove item numbers DNUMS from the list of expressions to display.
  2271.  
  2272. `disable display DNUMS...'
  2273.      Disable the display of item numbers DNUMS.  A disabled display
  2274.      item is not printed automatically, but is not forgotten.  It may be
  2275.      reenabled later.
  2276.  
  2277. `enable display DNUMS...'
  2278.      Enable display of item numbers DNUMS.  It becomes effective once
  2279.      again in auto display of its expression, until you specify
  2280.      otherwise.
  2281.  
  2282. `display'
  2283.      Display the current values of the expressions on the list, just as
  2284.      is done when the program stops.
  2285.  
  2286. `info display'
  2287.      Print the list of expressions previously set up to display
  2288.      automatically, each one with its item number, but without showing
  2289.      the values.  This includes disabled expressions, which are marked
  2290.      as such.  It also includes expressions which would not be
  2291.      displayed right now because they refer to automatic variables not
  2292.      currently available.
  2293.  
  2294. File: gdb.info,  Node: Value History,  Next: Convenience Vars,  Prev: Auto Display,  Up: Data
  2295.  
  2296. Value History
  2297. =============
  2298.  
  2299.    Every value printed by the `print' command is saved for the entire
  2300. session in GDB's "value history" so that you can refer to it in other
  2301. expressions.
  2302.  
  2303.    The values printed are given "history numbers" for you to refer to
  2304. them by.  These are successive integers starting with 1.  `print' shows
  2305. you the history number assigned to a value by printing `$NUM = ' before
  2306. the value; here NUM is the history number.
  2307.  
  2308.    To refer to any previous value, use `$' followed by the value's
  2309. history number.  The output printed by `print' is designed to remind
  2310. you of this.  Just `$' refers to the most recent value in the history,
  2311. and `$$' refers to the value before that.
  2312.  
  2313.    For example, suppose you have just printed a pointer to a structure
  2314. and want to see the contents of the structure.  It suffices to type
  2315.  
  2316.      p *$
  2317.  
  2318.    If you have a chain of structures where the component `next' points
  2319. to the next one, you can print the contents of the next one with this:
  2320.  
  2321.      p *$.next
  2322.  
  2323. It might be useful to repeat this command many times by typing RET.
  2324.  
  2325.    Note that the history records values, not expressions.  If the value
  2326. of `x' is 4 and you type this command:
  2327.  
  2328.      print x
  2329.      set x=5
  2330.  
  2331. then the value recorded in the value history by the `print' command
  2332. remains 4 even though the value of `x' has changed.
  2333.  
  2334. `info values'
  2335.      Print the last ten values in the value history, with their item
  2336.      numbers.  This is like `p $$9' repeated ten times, except that
  2337.      `info values' does not change the history.
  2338.  
  2339. `info values N'
  2340.      Print ten history values centered on history item number N.
  2341.  
  2342. `info values +'
  2343.      Print ten history values just after the values last printed.
  2344.  
  2345. File: gdb.info,  Node: Convenience Vars,  Next: Registers,  Prev: Value History,  Up: Data
  2346.  
  2347. Convenience Variables
  2348. =====================
  2349.  
  2350.    GDB provides "convenience variables" that you can use within GDB to
  2351. hold on to a value and refer to it later.  These variables exist
  2352. entirely within GDB; they are not part of your program, and setting a
  2353. convenience variable has no effect on further execution of your
  2354. program.  That's why you can use them freely.
  2355.  
  2356.    Convenience variables have names starting with `$'.  Any name
  2357. starting with `$' can be used for a convenience variable, unless it is
  2358. one of the predefined set of register names (*note Registers::.).
  2359.  
  2360.    You can save a value in a convenience variable with an assignment
  2361. expression, just as you would set a variable in your program.  Example:
  2362.  
  2363.      set $foo = *object_ptr
  2364.  
  2365. would save in `$foo' the value contained in the object pointed to by
  2366. `object_ptr'.
  2367.  
  2368.    Using a convenience variable for the first time creates it; but its
  2369. value is `void' until you assign a new value.  You can alter the value
  2370. with another assignment at any time.
  2371.  
  2372.    Convenience variables have no fixed types.  You can assign a
  2373. convenience variable any type of value, even if it already has a value
  2374. of a different type.  The convenience variable as an expression has
  2375. whatever type its current value has.
  2376.  
  2377. `info convenience'
  2378.      Print a list of convenience variables used so far, and their
  2379.      values.  Abbreviated `i con'.
  2380.  
  2381.    One of the ways to use a convenience variable is as a counter to be
  2382. incremented or a pointer to be advanced.  For example:
  2383.  
  2384.      set $i = 0
  2385.      print bar[$i++]->contents
  2386.      ...repeat that command by typing RET.
  2387.  
  2388.    Some convenience variables are created automatically by GDB and given
  2389. values likely to be useful.
  2390.  
  2391. `$_'
  2392.      The variable `$_' is automatically set by the `x' command to the
  2393.      last address examined (*note Memory::.).  Other commands which
  2394.      provide a default address for `x' to examine also set `$_' to that
  2395.      address; these commands include `info line' and `info breakpoint'.
  2396.  
  2397. `$__'
  2398.      The variable `$__' is automatically set by the `x' command to the
  2399.      value found in the last address examined.
  2400.  
  2401. File: gdb.info,  Node: Registers,  Prev: Convenience Vars,  Up: Data
  2402.  
  2403. Registers
  2404. =========
  2405.  
  2406.    Machine register contents can be referred to in expressions as
  2407. variables with names starting with `$'.  The names of registers are
  2408. different for each machine; use `info registers' to see the names used
  2409. on your machine.  The names `$pc' and `$sp' are used on all machines for
  2410. the program counter register and the stack pointer.  Often `$fp' is
  2411. used for a register that contains a pointer to the current stack frame,
  2412. and `$ps' is used for a register that contains the processor status.
  2413. These standard register names may be available on your machine even
  2414. though the `info registers' command displays them with a different
  2415. name.  For example, on the SPARC, `info registers' displays the
  2416. processor status register as `$psr' but you can also refer to it as
  2417. `$ps'.
  2418.  
  2419.    GDB always considers the contents of an ordinary register as an
  2420. integer when the register is examined in this way.  Some machines have
  2421. special registers which can hold nothing but floating point; these
  2422. registers are considered floating point.  There is no way to refer to
  2423. the contents of an ordinary register as floating point value (although
  2424. you can *print* it as a floating point value with `print/f $REGNAME').
  2425.  
  2426.    Some registers have distinct "raw" and "virtual" data formats.  This
  2427. means that the data format in which the register contents are saved by
  2428. the operating system is not the same one that your program normally
  2429. sees.  For example, the registers of the 68881 floating point
  2430. coprocessor are always saved in "extended" format, but all C programs
  2431. expect to work with "double" format.  In such cases, GDB normally works
  2432. with the virtual format only (the format that makes sense for your
  2433. program), but the `info registers' command prints the data in both
  2434. formats.
  2435.  
  2436.    Register values are relative to the selected stack frame (*note
  2437. Selection::.).  This means that you get the value that the register
  2438. would contain if all stack frames farther in were exited and their saved
  2439. registers restored.  In order to see the real contents of all registers,
  2440. you must select the innermost frame (with `frame 0').
  2441.  
  2442.    Some registers are never saved (typically those numbered zero or one)
  2443. because they are used for returning function values; for these
  2444. registers, relativization makes no difference.
  2445.  
  2446. `info registers'
  2447.      Print the names and relativized values of all registers.
  2448.  
  2449. `info registers REGNAME'
  2450.      Print the relativized value of register REGNAME.  REGNAME may be
  2451.      any register name valid on the machine you are using, with or
  2452.      without the initial `$'.
  2453.  
  2454. Examples
  2455. --------
  2456.  
  2457.    You could print the program counter in hex with
  2458.  
  2459.      p/x $pc
  2460.  
  2461. or print the instruction to be executed next with
  2462.  
  2463.      x/i $pc
  2464.  
  2465. or add four to the stack pointer with
  2466.  
  2467.      set $sp += 4
  2468.  
  2469. The last is a way of removing one word from the stack, on machines where
  2470. stacks grow downward in memory (most machines, nowadays).  This assumes
  2471. that the innermost stack frame is selected.  Setting `$sp' is not
  2472. allowed when other stack frames are selected.
  2473.  
  2474. File: gdb.info,  Node: Symbols,  Next: Altering,  Prev: Data,  Up: Top
  2475.  
  2476. Examining the Symbol Table
  2477. **************************
  2478.  
  2479.    The commands described in this section allow you to make inquiries
  2480. for information about the symbols (names of variables, functions and
  2481. types) defined in your program.  This information is found by GDB in
  2482. the symbol table loaded by the `symbol-file' command; it is inherent in
  2483. the text of your program and does not change as the program executes.
  2484.  
  2485. `whatis EXP'
  2486.      Print the data type of expression EXP.  EXP is not actually
  2487.      evaluated, and any side-effecting operations (such as assignments
  2488.      or function calls) inside it do not take place.  *Note
  2489.      Expressions::.
  2490.  
  2491. `whatis'
  2492.      Print the data type of `$', the last value in the value history.
  2493.  
  2494. `info address SYMBOL'
  2495.      Describe where the data for SYMBOL is stored.  For a register
  2496.      variable, this says which register it is kept in.  For a
  2497.      non-register local variable, this prints the stack-frame offset at
  2498.      which the variable is always stored.
  2499.  
  2500.      Note the contrast with `print &SYMBOL', which does not work at all
  2501.      for a register variables, and for a stack local variable prints
  2502.      the exact address of the current instantiation of the variable.
  2503.  
  2504. `ptype TYPENAME'
  2505.      Print a description of data type TYPENAME.  TYPENAME may be the
  2506.      name of a type, or for C code it may have the form `struct
  2507.      STRUCT-TAG', `union UNION-TAG' or `enum ENUM-TAG'.
  2508.  
  2509. `info sources'
  2510.      Print the names of all source files in the program for which there
  2511.      is debugging information.
  2512.  
  2513. `info functions'
  2514.      Print the names and data types of all defined functions.
  2515.  
  2516. `info functions REGEXP'
  2517.      Print the names and data types of all defined functions whose
  2518.      names contain a match for regular expression REGEXP.  Thus, `info
  2519.      fun step' finds all functions whose names include `step'; `info
  2520.      fun ^step' finds those whose names start with `step'.
  2521.  
  2522. `info variables'
  2523.      Print the names and data types of all variables that are declared
  2524.      outside of functions (i.e., except for local variables).
  2525.  
  2526. `info variables REGEXP'
  2527.      Print the names and data types of all variables (except for local
  2528.      variables) whose names contain a match for regular expression
  2529.      REGEXP.
  2530.  
  2531. `info types'
  2532.      Print all data types that are defined in the program.
  2533.  
  2534. `info types REGEXP'
  2535.      Print all data types that are defined in the program whose names
  2536.      contain a match for regular expression REGEXP.
  2537.  
  2538. `printsyms FILENAME'
  2539.      Write a complete dump of the debugger's symbol data into the file
  2540.      FILENAME.
  2541.  
  2542. File: gdb.info,  Node: Altering,  Next: Sequences,  Prev: Symbols,  Up: Top
  2543.  
  2544. Altering Execution
  2545. ******************
  2546.  
  2547.    Once you think you have find an error in the program, you might want
  2548. to find out for certain whether correcting the apparent error would
  2549. lead to correct results in the rest of the run.  You can find the
  2550. answer by experiment, using the GDB features for altering execution of
  2551. the program.
  2552.  
  2553.    For example, you can store new values into variables or memory
  2554. locations, give the program a signal, restart it at a different address,
  2555. or even return prematurely from a function to its caller.
  2556.  
  2557. * Menu:
  2558.  
  2559. * Assignment::    Altering variable values or memory contents.
  2560. * Jumping::       Altering control flow.
  2561. * Signaling::     Making signals happen in the program.
  2562. * Returning::     Making a function return prematurely.
  2563.  
  2564. File: gdb.info,  Node: Assignment,  Next: Jumping,  Prev: Altering,  Up: Altering
  2565.  
  2566. Assignment to Variables
  2567. =======================
  2568.  
  2569.    To alter the value of a variable, evaluate an assignment expression.
  2570. *Note Expressions::.  For example,
  2571.  
  2572.      print x=4
  2573.  
  2574. would store the value 4 into the variable `x', and then print the value
  2575. of the assignment expression (which is 4).
  2576.  
  2577.    All the assignment operators of C are supported, including the
  2578. incrementation operators `++' and `--', and combining assignments such
  2579. as `+=' and `<<='.
  2580.  
  2581.    If you are not interested in seeing the value of the assignment, use
  2582. the `set' command instead of the `print' command.  `set' is really the
  2583. same as `print' except that the expression's value is not printed and
  2584. is not put in the value history (*note Value History::.).  The
  2585. expression is evaluated only for side effects.
  2586.  
  2587.    Note that if the beginning of the argument string of the `set'
  2588. command appears identical to a `set' subcommand, it may be necessary to
  2589. use the `set variable' command.  This command is identical to `set'
  2590. except for its lack of subcommands.
  2591.  
  2592.    GDB allows more implicit conversions in assignments than C does; you
  2593. can freely store an integer value into a pointer variable or vice
  2594. versa, and any structure can be converted to any other structure that
  2595. is the same length or shorter.
  2596.  
  2597.    To store values into arbitrary places in memory, use the `{...}'
  2598. construct to generate a value of specified type at a specified address
  2599. (*note Expressions::.).  For example, `{int}0x83040' would refer to
  2600. memory location 0x83040 as an integer (which implies a certain size and
  2601. representation in memory), and
  2602.  
  2603.      set {int}0x83040 = 4
  2604.  
  2605.    would store the value 4 into that memory location.
  2606.  
  2607. File: gdb.info,  Node: Jumping,  Next: Signaling,  Prev: Assignment,  Up: Altering
  2608.  
  2609. Continuing at a Different Address
  2610. =================================
  2611.  
  2612.    Ordinarily, when you continue the program, you do so at the place
  2613. where it stopped, with the `cont' command.  You can instead continue at
  2614. an address of your own choosing, with the following commands:
  2615.  
  2616. `jump LINENUM'
  2617.      Resume execution at line number LINENUM.  Execution may stop
  2618.      immediately if there is a breakpoint there.
  2619.  
  2620.      The `jump' command does not change the current stack frame, or the
  2621.      stack pointer, or the contents of any memory location or any
  2622.      register other than the program counter.  If line LINENUM is in a
  2623.      different function from the one currently executing, the results
  2624.      may be bizarre if the two functions expect different patterns of
  2625.      arguments or of local variables.  For this reason, the `jump'
  2626.      command requests confirmation if the specified line is not in the
  2627.      function currently executing.  However, even bizarre results are
  2628.      predictable based on careful study of the machine-language code of
  2629.      the program.
  2630.  
  2631. `jump *ADDRESS'
  2632.      Resume execution at the instruction at address ADDRESS.
  2633.  
  2634.    You can get much the same effect as the `jump' command by storing a
  2635. new value into the register `$pc'.  The difference is that this does
  2636. not start the program running; it only changes the address where it
  2637. *will* run when it is continued.  For example,
  2638.  
  2639.      set $pc = 0x485
  2640.  
  2641. causes the next `cont' command or stepping command to execute at
  2642. address 0x485, rather than at the address where the program stopped.
  2643. *Note Stepping::.
  2644.  
  2645.    The most common occasion to use the `jump' command is when you have
  2646. stepped across a function call with `next', and found that the return
  2647. value is incorrect.  If all the relevant data appeared correct before
  2648. the function call, the error is probably in the function that just
  2649. returned.
  2650.  
  2651.    In general, your next step would now be to rerun the program and
  2652. execute up to this function call, and then step into it to see where it
  2653. goes astray.  But this may be time consuming.  If the function did not
  2654. have significant side effects, you could get the same information by
  2655. resuming execution just before the function call and stepping through
  2656. it.  To do this, first put a breakpoint on that function; then, use the
  2657. `jump' command to continue on the line with the function call.
  2658.  
  2659. File: gdb.info,  Node: Signaling,  Next: Returning,  Prev: Jumping,  Up: Altering
  2660.  
  2661. Giving the Program a Signal
  2662. ===========================
  2663.  
  2664. `signal SIGNALNUM'
  2665.      Resume execution where the program stopped, but give it
  2666.      immediately the signal number SIGNALNUM.
  2667.  
  2668.      Alternatively, if SIGNALNUM is zero, continue execution without
  2669.      giving a signal.  This is useful when the program stopped on
  2670.      account of a signal and would ordinary see the signal when resumed
  2671.      with the `cont' command; `signal 0' causes it to resume without a
  2672.      signal.
  2673.  
  2674. File: gdb.info,  Node: Returning,  Prev: Signaling,  Up: Altering
  2675.  
  2676. Returning from a Function
  2677. =========================
  2678.  
  2679.    You can cancel execution of a function call with the `return'
  2680. command.  This command has the effect of discarding the selected stack
  2681. frame (and all frames within it), so that control moves to the caller of
  2682. that function.  You can think of this as making the discarded frame
  2683. return prematurely.
  2684.  
  2685.    First select the stack frame that you wish to return from (*note
  2686. Selection::.).  Then type the `return' command.  If you wish to specify
  2687. the value to be returned, give that as an argument.
  2688.  
  2689.    This pops the selected stack frame (and any other frames inside of
  2690. it), leaving its caller as the innermost remaining frame.  That frame
  2691. becomes selected.  The specified value is stored in the registers used
  2692. for returning values of functions.
  2693.  
  2694.    The `return' command does not resume execution; it leaves the
  2695. program stopped in the state that would exist if the function had just
  2696. returned.  Contrast this with the `finish' command (*note Stepping::.),
  2697. which resumes execution until the selected stack frame returns
  2698. *naturally*.
  2699.  
  2700. File: gdb.info,  Node: Sequences,  Next: Options,  Prev: Altering,  Up: Top
  2701.  
  2702. Canned Sequences of Commands
  2703. ****************************
  2704.  
  2705.    GDB provides two ways to store sequences of commands for execution
  2706. as a unit: user-defined commands and command files.
  2707.  
  2708. * Menu:
  2709.  
  2710. * Define::         User-defined commands.
  2711. * Command Files::  Command files.
  2712. * Output::         Controlled output commands useful in
  2713.                    user-defined commands and command files.
  2714.  
  2715. File: gdb.info,  Node: Define,  Next: Command Files,  Prev: Sequences,  Up: Sequences
  2716.  
  2717. User-Defined Commands
  2718. =====================
  2719.  
  2720.    A "user-defined command" is a sequence of GDB commands to which you
  2721. assign a new name as a command.  This is done with the `define' command.
  2722.  
  2723. `define COMMANDNAME'
  2724.      Define a command named COMMANDNAME.  If there is already a command
  2725.      by that name, you are asked to confirm that you want to redefine
  2726.      it.
  2727.  
  2728.      The definition of the command is made up of other GDB command
  2729.      lines, which are given following the `define' command.  The end of
  2730.      these commands is marked by a line containing `end'.
  2731.  
  2732. `document COMMANDNAME'
  2733.      Give documentation to the user-defined command COMMANDNAME.  The
  2734.      command COMMANDNAME must already be defined.  This command reads
  2735.      lines of documentation just as `define' reads the lines of the
  2736.      command definition, ending with `end'.  After the `document'
  2737.      command is finished, `help' on command COMMANDNAME will print the
  2738.      documentation you have specified.
  2739.  
  2740.      You may use the `document' command again to change the
  2741.      documentation of a command.  Redefining the command with `define'
  2742.      does not change the documentation.
  2743.  
  2744.    User-defined commands do not take arguments.  When they are
  2745. executed, the commands of the definition are not printed.  An error in
  2746. any command stops execution of the user-defined command.
  2747.  
  2748.    Commands that would ask for confirmation if used interactively
  2749. proceed without asking when used inside a user-defined command.  Many
  2750. GDB commands that normally print messages to say what they are doing
  2751. omit the messages when used in user-defined command.
  2752.  
  2753. File: gdb.info,  Node: Command Files,  Next: Output,  Prev: Define,  Up: Sequences
  2754.  
  2755. Command Files
  2756. =============
  2757.  
  2758.    A command file for GDB is a file of lines that are GDB commands.
  2759. Comments (lines starting with `#') may also be included.  An empty line
  2760. in a command file does nothing; it does not mean to repeat the last
  2761. command, as it would from the terminal.
  2762.  
  2763.    When GDB starts, it automatically executes its "init files", command
  2764. files named `.gdbinit'.  GDB reads the init file (if any) in your home
  2765. directory and then the init file (if any) in the current working
  2766. directory.  (The init files are not executed if the `-nx' option is
  2767. given.)  You can also request the execution of a command file with the
  2768. `source' command:
  2769.  
  2770. `source FILENAME'
  2771.      Execute the command file FILENAME.
  2772.  
  2773.    The lines in a command file are executed sequentially.  They are not
  2774. printed as they are executed.  An error in any command terminates
  2775. execution of the command file.
  2776.  
  2777.    Commands that would ask for confirmation if used interactively
  2778. proceed without asking when used in a command file.  Many GDB commands
  2779. that normally print messages to say what they are doing omit the
  2780. messages when used in a command file.
  2781.  
  2782. File: gdb.info,  Node: Output,  Prev: Command Files,  Up: Sequences
  2783.  
  2784. Commands for Controlled Output
  2785. ==============================
  2786.  
  2787.    During the execution of a command file or a user-defined command,
  2788. the only output that appears is what is explicitly printed by the
  2789. commands of the definition.  This section describes three commands
  2790. useful for generating exactly the output you want.
  2791.  
  2792. `echo TEXT'
  2793.      Print TEXT.  Nonprinting characters can be included in TEXT using
  2794.      C escape sequences, such as `\n' to print a newline.  No newline
  2795.      will be printed unless you specify one. In addition to the
  2796.      standard C escape sequences a backslash followed by a space stands
  2797.      for a space.  This is useful for outputting a string with spaces
  2798.      at the beginning or the end, since leading and trailing spaces are
  2799.      trimmed from all arguments.  Thus, to print " and foo = ", use the
  2800.      command "echo \ and foo = \ ".
  2801.  
  2802.      A backslash at the end of TEXT can be used, as in C, to continue
  2803.      the command onto subsequent lines.  For example,
  2804.  
  2805.           echo This is some text\n\
  2806.           which is continued\n\
  2807.           onto several lines.\n
  2808.  
  2809.      produces the same output as
  2810.  
  2811.           echo This is some text\n
  2812.           echo which is continued\n
  2813.           echo onto several lines.\n
  2814.  
  2815. `output EXPRESSION'
  2816.      Print the value of EXPRESSION and nothing but that value: no
  2817.      newlines, no `$NN = '.  The value is not entered in the value
  2818.      history either.  *Note Expressions:: for more information on
  2819.      expressions.
  2820.  
  2821. `output/FMT EXPRESSION'
  2822.      Print the value of EXPRESSION in format FMT.  *Note Output
  2823.      formats::, for more information.
  2824.  
  2825. `printf STRING, EXPRESSIONS...'
  2826.      Print the values of the EXPRESSIONS under the control of STRING.
  2827.      The EXPRESSIONS are separated by commas and may be either numbers
  2828.      or pointers.  Their values are printed as specified by STRING,
  2829.      exactly as if the program were to execute
  2830.  
  2831.           printf (STRING, EXPRESSIONS...);
  2832.  
  2833.      For example, you can print two values in hex like this:
  2834.  
  2835.           printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
  2836.  
  2837.      The only backslash-escape sequences that you can use in the string
  2838.      are the simple ones that consist of backslash followed by a letter.
  2839.  
  2840. File: gdb.info,  Node: Options,  Next: Emacs,  Prev: Sequences,  Up: Top
  2841.  
  2842. Options and Arguments for GDB
  2843. *****************************
  2844.  
  2845.    When you invoke GDB, you can specify arguments telling it what files
  2846. to operate on and what other things to do.
  2847.  
  2848. * Menu:
  2849.  
  2850. * Mode Options::     Options controlling modes of operation.
  2851. * File Options::     Options to specify files (executable, coredump, commands)
  2852. * Other Arguments::  Any other arguments without options
  2853.             also specify files.
  2854.  
  2855. File: gdb.info,  Node: Mode Options,  Next: File Options,  Prev: Options,  Up: Options
  2856.  
  2857. Mode Options
  2858. ============
  2859.  
  2860. `-nx'
  2861.      Do not execute commands from the init files `.gdbinit'.  Normally,
  2862.      the commands in these files are executed after all the command
  2863.      options and arguments have been processed.  *Note Command Files::.
  2864.  
  2865. `-q'
  2866.      "Quiet".  Do not print the usual introductory messages.
  2867.  
  2868. `-batch'
  2869.      Run in batch mode.  Exit with code 0 after processing all the
  2870.      command files specified with `-x' (and `.gdbinit', if not
  2871.      inhibited).  Exit with nonzero status if an error occurs in
  2872.      executing the GDB commands in the command files.
  2873.  
  2874. `-fullname'
  2875.      This option is used when Emacs runs GDB as a subprocess.  It tells
  2876.      GDB to output the full file name and line number in a standard,
  2877.      recognizable fashion each time a stack frame is displayed (which
  2878.      includes each time the program stops).  This recognizable format
  2879.      looks like two `\032' characters, followed by the file name, line
  2880.      number and character position separated by colons, and a newline.
  2881.      The Emacs-to-GDB interface program uses the two `\032' characters
  2882.      as a signal to display the source code for the frame.
  2883.  
  2884. File: gdb.info,  Node: File Options,  Next: Other Arguments,  Prev: Mode Options,  Up: Options
  2885.  
  2886. File-specifying Options
  2887. =======================
  2888.  
  2889.    All the options and command line arguments given are processed in
  2890. sequential order.  The order makes a difference when the `-x' option is
  2891. used.
  2892.  
  2893. `-s FILE'
  2894.      Read symbol table from file FILE.
  2895.  
  2896. `-e FILE'
  2897.      Use file FILE as the executable file to execute when appropriate,
  2898.      and for examining pure data in conjunction with a core dump.
  2899.  
  2900. `-se FILE'
  2901.      Read symbol table from file FILE and use it as the executable file.
  2902.  
  2903. `-c FILE'
  2904.      Use file FILE as a core dump to examine.
  2905.  
  2906. `-x FILE'
  2907.      Execute GDB commands from file FILE.
  2908.  
  2909. `-d DIRECTORY'
  2910.      Add DIRECTORY to the path to search for source files.
  2911.  
  2912. File: gdb.info,  Node: Other Arguments,  Prev: File Options,  Up: Options
  2913.  
  2914. Other Arguments
  2915. ===============
  2916.  
  2917.    If there are arguments to GDB that are not options or associated with
  2918. options, the first one specifies the symbol table and executable file
  2919. name (as if it were preceded by `-se') and the second one specifies a
  2920. core dump file name (as if it were preceded by `-c').
  2921.  
  2922. File: gdb.info,  Node: Emacs,  Next: Remote,  Prev: Options,  Up: Top
  2923.  
  2924. Using GDB under GNU Emacs
  2925. *************************
  2926.  
  2927.    A special interface allows you to use GNU Emacs to view (and edit)
  2928. the source files for the program you are debugging with GDB.
  2929.  
  2930.    To use this interface, use the command `M-x gdb' in Emacs.  Give the
  2931. executable file you want to debug as an argument.  This command starts
  2932. GDB as a subprocess of Emacs, with input and output through a newly
  2933. created Emacs buffer.
  2934.  
  2935.    Using GDB under Emacs is just like using GDB normally except for two
  2936. things:
  2937.  
  2938.    * All "terminal" input and output goes through the Emacs buffer.
  2939.      This applies both to GDB commands and their output, and to the
  2940.      input and output done by the program you are debugging.
  2941.  
  2942.      This is useful because it means that you can copy the text of
  2943.      previous commands and input them again; you can even use parts of
  2944.      the output in this way.
  2945.  
  2946.      All the facilities of Emacs's Shell mode are available for this
  2947.      purpose.
  2948.  
  2949.    * GDB displays source code through Emacs.  Each time GDB displays a
  2950.      stack frame, Emacs automatically finds the source file for that
  2951.      frame and puts an arrow (`=>') at the left margin of the current
  2952.      line.
  2953.  
  2954.      Explicit GDB `list' or search commands still produce output as
  2955.      usual, but you probably will have no reason to use them.
  2956.  
  2957.    In the GDB I/O buffer, you can use these special Emacs commands:
  2958.  
  2959. `M-s'
  2960.      Execute to another source line, like the GDB `step' command.
  2961.  
  2962. `M-n'
  2963.      Execute to next source line in this function, skipping all function
  2964.      calls, like the GDB `next' command.
  2965.  
  2966. `M-i'
  2967.      Execute one instruction, like the GDB `stepi' command.
  2968.  
  2969. `C-c C-f'
  2970.      Execute until exit from the selected stack frame, like the GDB
  2971.      `finish' command.
  2972.  
  2973. `M-c'
  2974.      Continue execution of the program, like the GDB `cont' command.
  2975.  
  2976. `M-u'
  2977.      Go up the number of frames indicated by the numeric argument
  2978.      (*note Numeric Arguments: (emacs)Arguments.), like the GDB `up'
  2979.      command.
  2980.  
  2981. `M-d'
  2982.      Go down the number of frames indicated by the numeric argument,
  2983.      like the GDB `down' command.
  2984.  
  2985.    In any source file, the Emacs command `C-x SPC' (`gdb-break') tells
  2986. GDB to set a breakpoint on the source line point is on.
  2987.  
  2988.    The source files displayed in Emacs are in ordinary Emacs buffers
  2989. which are visiting the source files in the usual way.  You can edit the
  2990. files with these buffers if you wish; but keep in mind that GDB
  2991. communicates with Emacs in terms of line numbers.  If you add or delete
  2992. lines from the text, the line numbers that GDB knows will cease to
  2993. correspond properly to the code.
  2994.  
  2995. File: gdb.info,  Node: Remote,  Next: Commands,  Prev: Emacs,  Up: Top
  2996.  
  2997. Remote Kernel Debugging
  2998. ***********************
  2999.  
  3000.    If you are trying to debug a program running on a machine that can't
  3001. run GDB in the usual way, it is often useful to use remote debugging.
  3002. For example, you might be debugging an operating system kernel, or
  3003. debugging a small system which does not have a general purpose
  3004. operating system powerful enough to run a full-featured debugger.
  3005. Currently GDB supports remote debugging over a serial connection.
  3006.  
  3007.    The program to be debugged on the remote machine needs to contain a
  3008. debugging device driver which talks to GDB over the serial line using
  3009. the protocol described below.  The same version of GDB that is used
  3010. ordinarily can be used for this.  Several sample remote debugging
  3011. drivers are distributed with GDB; see the `README' file in the GDB
  3012. distribution for more information.
  3013.  
  3014. * Menu:
  3015.  
  3016. * Remote Commands::       Commands used to start and finish remote debugging.
  3017.  
  3018.    For details of the communication protocol, see the comments in the
  3019. GDB source file `remote.c'.
  3020.  
  3021. File: gdb.info,  Node: Remote Commands,  Prev: Remote,  Up: Remote
  3022.  
  3023. Commands for Remote Debugging
  3024. =============================
  3025.  
  3026.    To start remote debugging, first run GDB and specify as an
  3027. executable file the program that is running in the remote machine.
  3028. This tells GDB how to find the program's symbols and the contents of
  3029. its pure text.  Then establish communication using the `attach' command
  3030. with a device name rather than a pid as an argument.  For example:
  3031.  
  3032.      attach /dev/ttyd
  3033.  
  3034. if the serial line is connected to the device named `/dev/ttyd'.  This
  3035. will stop the remote machine if it is not already stopped.
  3036.  
  3037.    Now you can use all the usual commands to examine and change data
  3038. and to step and continue the remote program.
  3039.  
  3040.    To resume the remote program and stop debugging it, use the `detach'
  3041. command.
  3042.  
  3043. File: gdb.info,  Node: Commands,  Next: Concepts,  Prev: Remote,  Up: Top
  3044.  
  3045. Command Index
  3046. *************
  3047.  
  3048. * Menu:
  3049.  
  3050. * $_:                                   Breakpoints.
  3051. * $_:                                   List.
  3052. * $_:                                   Memory.
  3053. * $__:                                  Memory.
  3054. * $$:                                   Value History.
  3055. * $:                                    Value History.
  3056. * .gdbinit:                             Command Files.
  3057. * abbreviation:                         User Interface.
  3058. * add-file:                             File Commands.
  3059. * arguments (to your program):          Arguments.
  3060. * artificial array:                     Arrays.
  3061. * assignment:                           Assignment.
  3062. * attach:                               Attach.
  3063. * attach:                               Attach.
  3064. * automatic display:                    Auto Display.
  3065. * backtrace:                            Backtrace.
  3066. * break:                                Set Breaks.
  3067. * breakpoint commands:                  Break Commands.
  3068. * breakpoint conditions:                Conditions.
  3069. * breakpoints:                          Breakpoints.
  3070. * bt:                                   Backtrace.
  3071. * call stack:                           Stack.
  3072. * cd:                                   Working Directory.
  3073. * clear:                                Delete Breaks.
  3074. * clearing breakpoint:                  Delete Breaks.
  3075. * command files:                        Command Files.
  3076. * condition:                            Conditions.
  3077. * conditional breakpoints:              Conditions.
  3078. * cont:                                 Continuing.
  3079. * controlling terminal:                 Input/Output.
  3080. * convenience variables:                Convenience Vars.
  3081. * core dump file:                       Files.
  3082. * core-file:                            File Commands.
  3083. * define:                               Define.
  3084. * delete:                               Delete Breaks.
  3085. * delete display:                       Auto Display.
  3086. * delete environment:                   Environment.
  3087. * deleting breakpoints:                 Delete Breaks.
  3088. * detach:                               Attach.
  3089. * directories for source files:         Source Path.
  3090. * directory:                            Source Path.
  3091. * disable:                              Disabling.
  3092. * disable breakpoints:                  Disabling.
  3093. * disable display:                      Auto Display.
  3094. * disabled breakpoints:                 Disabling.
  3095. * disassemble:                          Memory.
  3096. * display:                              Auto Display.
  3097. * display of expressions:               Auto Display.
  3098. * document:                             Define.
  3099. * down:                                 Selection.
  3100. * dynamic linking:                      File Commands.
  3101. * echo:                                 Output.
  3102. * enable:                               Disabling.
  3103. * enable breakpoints:                   Disabling.
  3104. * enable display:                       Auto Display.
  3105. * enabled breakpoints:                  Disabling.
  3106. * environment (of your program):        Environment.
  3107. * examining data:                       Data.
  3108. * examining memory:                     Memory.
  3109. * exec-file:                            File Commands.
  3110. * executable file:                      Files.
  3111. * exiting GDB:                          User Interface.
  3112. * expressions:                          Expressions.
  3113. * fatal signals:                        Signals.
  3114. * finish:                               Stepping.
  3115. * format options:                       Format options.
  3116. * formatted output:                     Output formats.
  3117. * forward-search:                       Search.
  3118. * frame:                                Frames.
  3119. * frame:                                Selection.
  3120. * frame number:                         Frames.
  3121. * frame pointer:                        Frames.
  3122. * frameless execution:                  Frames.
  3123. * handle:                               Signals.
  3124. * handling signals:                     Signals.
  3125. * history number:                       Value History.
  3126. * ignore:                               Conditions.
  3127. * ignore count (of breakpoint):         Conditions.
  3128. * info address:                         Symbols.
  3129. * info args:                            Frame Info.
  3130. * info break:                           Breakpoints.
  3131. * info convenience:                     Convenience Vars.
  3132. * info directories:                     Source Path.
  3133. * info display:                         Auto Display.
  3134. * info environment:                     Environment.
  3135. * info files:                           File Commands.
  3136. * info format:                          Format options.
  3137. * info frame:                           Frame Info.
  3138. * info functions:                       Symbols.
  3139. * info line:                            List.
  3140. * info locals:                          Frame Info.
  3141. * info registers:                       Registers.
  3142. * info signal:                          Signals.
  3143. * info sources:                         Symbols.
  3144. * info stack:                           Backtrace.
  3145. * info types:                           Symbols.
  3146. * info values:                          Value History.
  3147. * info variables:                       Symbols.
  3148. * init file:                            Command Files.
  3149. * initial frame:                        Frames.
  3150. * innermost frame:                      Frames.
  3151. * jump:                                 Jumping.
  3152. * kill:                                 Kill Process.
  3153. * linespec:                             List.
  3154. * list:                                 List.
  3155. * next:                                 Stepping.
  3156. * nexti:                                Stepping.
  3157. * ni:                                   Stepping.
  3158. * outermost frame:                      Frames.
  3159. * output:                               Output.
  3160. * output formats:                       Output formats.
  3161. * pauses in output:                     User Interface.
  3162. * print:                                Data.
  3163. * printf:                               Output.
  3164. * printing data:                        Data.
  3165. * printsyms:                            Symbols.
  3166. * prompt:                               User Interface.
  3167. * ptype:                                Symbols.
  3168. * pwd:                                  Working Directory.
  3169. * quit:                                 User Interface.
  3170. * redirection:                          Input/Output.
  3171. * registers:                            Registers.
  3172. * repeating commands:                   User Interface.
  3173. * return:                               Returning.
  3174. * returning from a function:            Returning.
  3175. * reverse-search:                       Search.
  3176. * run:                                  Running.
  3177. * running:                              Running.
  3178. * screen size:                          User Interface.
  3179. * searching:                            Search.
  3180. * selected frame:                       Frames.
  3181. * set:                                  Assignment.
  3182. * set args:                             Arguments.
  3183. * set array-max:                        Format options.
  3184. * set environment:                      Environment.
  3185. * set prettyprint:                      Format options.
  3186. * set prompt:                           User Interface.
  3187. * set screensize:                       User Interface.
  3188. * set unionprint:                       Format options.
  3189. * set variable:                         Assignment.
  3190. * set verbose:                          User Interface.
  3191. * setting variables:                    Assignment.
  3192. * si:                                   Stepping.
  3193. * signal:                               Signaling.
  3194. * signals:                              Signals.
  3195. * silent:                               Break Commands.
  3196. * source:                               Command Files.
  3197. * source path:                          Source Path.
  3198. * stack frame:                          Frames.
  3199. * step:                                 Stepping.
  3200. * stepi:                                Stepping.
  3201. * stepping:                             Stepping.
  3202. * symbol table:                         Files.
  3203. * symbol-file:                          File Commands.
  3204. * tbreak:                               Set Breaks.
  3205. * tty:                                  Input/Output.
  3206. * undisplay:                            Auto Display.
  3207. * unset environment:                    Environment.
  3208. * until:                                Stepping.
  3209. * up:                                   Selection.
  3210. * user-defined command:                 Define.
  3211. * value history:                        Value History.
  3212. * whatis:                               Symbols.
  3213. * where:                                Backtrace.
  3214. * word:                                 Memory.
  3215. * working directory (of your program):  Working Directory.
  3216. * x:                                    Memory.
  3217.  
  3218. File: gdb.info,  Node: Concepts,  Prev: Commands,  Up: Top
  3219.  
  3220. Concept Index
  3221. *************
  3222.  
  3223. * Menu:
  3224.  
  3225. * $_:                                   Breakpoints.
  3226. * $_:                                   List.
  3227. * $_:                                   Memory.
  3228. * $__:                                  Memory.
  3229. * $$:                                   Value History.
  3230. * $:                                    Value History.
  3231. * .gdbinit:                             Command Files.
  3232. * abbreviation:                         User Interface.
  3233. * add-file:                             File Commands.
  3234. * arguments (to your program):          Arguments.
  3235. * artificial array:                     Arrays.
  3236. * assignment:                           Assignment.
  3237. * attach:                               Attach.
  3238. * attach:                               Attach.
  3239. * automatic display:                    Auto Display.
  3240. * backtrace:                            Backtrace.
  3241. * break:                                Set Breaks.
  3242. * breakpoint commands:                  Break Commands.
  3243. * breakpoint conditions:                Conditions.
  3244. * breakpoints:                          Breakpoints.
  3245. * bt:                                   Backtrace.
  3246. * call stack:                           Stack.
  3247. * cd:                                   Working Directory.
  3248. * clear:                                Delete Breaks.
  3249. * clearing breakpoint:                  Delete Breaks.
  3250. * command files:                        Command Files.
  3251. * condition:                            Conditions.
  3252. * conditional breakpoints:              Conditions.
  3253. * cont:                                 Continuing.
  3254. * controlling terminal:                 Input/Output.
  3255. * convenience variables:                Convenience Vars.
  3256. * core dump file:                       Files.
  3257. * core-file:                            File Commands.
  3258. * define:                               Define.
  3259. * delete:                               Delete Breaks.
  3260. * delete display:                       Auto Display.
  3261. * delete environment:                   Environment.
  3262. * deleting breakpoints:                 Delete Breaks.
  3263. * detach:                               Attach.
  3264. * directories for source files:         Source Path.
  3265. * directory:                            Source Path.
  3266. * disable:                              Disabling.
  3267. * disable breakpoints:                  Disabling.
  3268. * disable display:                      Auto Display.
  3269. * disabled breakpoints:                 Disabling.
  3270. * disassemble:                          Memory.
  3271. * display:                              Auto Display.
  3272. * display of expressions:               Auto Display.
  3273. * document:                             Define.
  3274. * down:                                 Selection.
  3275. * dynamic linking:                      File Commands.
  3276. * echo:                                 Output.
  3277. * enable:                               Disabling.
  3278. * enable breakpoints:                   Disabling.
  3279. * enable display:                       Auto Display.
  3280. * enabled breakpoints:                  Disabling.
  3281. * environment (of your program):        Environment.
  3282. * examining data:                       Data.
  3283. * examining memory:                     Memory.
  3284. * exec-file:                            File Commands.
  3285. * executable file:                      Files.
  3286. * exiting GDB:                          User Interface.
  3287. * expressions:                          Expressions.
  3288. * fatal signals:                        Signals.
  3289. * finish:                               Stepping.
  3290. * format options:                       Format options.
  3291. * formatted output:                     Output formats.
  3292. * forward-search:                       Search.
  3293. * frame:                                Frames.
  3294. * frame:                                Selection.
  3295. * frame number:                         Frames.
  3296. * frame pointer:                        Frames.
  3297. * frameless execution:                  Frames.
  3298. * handle:                               Signals.
  3299. * handling signals:                     Signals.
  3300. * history number:                       Value History.
  3301. * ignore:                               Conditions.
  3302. * ignore count (of breakpoint):         Conditions.
  3303. * info address:                         Symbols.
  3304. * info args:                            Frame Info.
  3305. * info break:                           Breakpoints.
  3306. * info convenience:                     Convenience Vars.
  3307. * info directories:                     Source Path.
  3308. * info display:                         Auto Display.
  3309. * info environment:                     Environment.
  3310. * info files:                           File Commands.
  3311. * info format:                          Format options.
  3312. * info frame:                           Frame Info.
  3313. * info functions:                       Symbols.
  3314. * info line:                            List.
  3315. * info locals:                          Frame Info.
  3316. * info registers:                       Registers.
  3317. * info signal:                          Signals.
  3318. * info sources:                         Symbols.
  3319. * info stack:                           Backtrace.
  3320. * info types:                           Symbols.
  3321. * info values:                          Value History.
  3322. * info variables:                       Symbols.
  3323. * init file:                            Command Files.
  3324. * initial frame:                        Frames.
  3325. * innermost frame:                      Frames.
  3326. * jump:                                 Jumping.
  3327. * kill:                                 Kill Process.
  3328. * linespec:                             List.
  3329. * list:                                 List.
  3330. * next:                                 Stepping.
  3331. * nexti:                                Stepping.
  3332. * ni:                                   Stepping.
  3333. * outermost frame:                      Frames.
  3334. * output:                               Output.
  3335. * output formats:                       Output formats.
  3336. * pauses in output:                     User Interface.
  3337. * print:                                Data.
  3338. * printf:                               Output.
  3339. * printing data:                        Data.
  3340. * printsyms:                            Symbols.
  3341. * prompt:                               User Interface.
  3342. * ptype:                                Symbols.
  3343. * pwd:                                  Working Directory.
  3344. * quit:                                 User Interface.
  3345. * redirection:                          Input/Output.
  3346. * registers:                            Registers.
  3347. * repeating commands:                   User Interface.
  3348. * return:                               Returning.
  3349. * returning from a function:            Returning.
  3350. * reverse-search:                       Search.
  3351. * run:                                  Running.
  3352. * running:                              Running.
  3353. * screen size:                          User Interface.
  3354. * searching:                            Search.
  3355. * selected frame:                       Frames.
  3356. * set:                                  Assignment.
  3357. * set args:                             Arguments.
  3358. * set array-max:                        Format options.
  3359. * set environment:                      Environment.
  3360. * set prettyprint:                      Format options.
  3361. * set prompt:                           User Interface.
  3362. * set screensize:                       User Interface.
  3363. * set unionprint:                       Format options.
  3364. * set variable:                         Assignment.
  3365. * set verbose:                          User Interface.
  3366. * setting variables:                    Assignment.
  3367. * si:                                   Stepping.
  3368. * signal:                               Signaling.
  3369. * signals:                              Signals.
  3370. * silent:                               Break Commands.
  3371. * source:                               Command Files.
  3372. * source path:                          Source Path.
  3373. * stack frame:                          Frames.
  3374. * step:                                 Stepping.
  3375. * stepi:                                Stepping.
  3376. * stepping:                             Stepping.
  3377. * symbol table:                         Files.
  3378. * symbol-file:                          File Commands.
  3379. * tbreak:                               Set Breaks.
  3380. * tty:                                  Input/Output.
  3381. * undisplay:                            Auto Display.
  3382. * unset environment:                    Environment.
  3383. * until:                                Stepping.
  3384. * up:                                   Selection.
  3385. * user-defined command:                 Define.
  3386. * value history:                        Value History.
  3387. * whatis:                               Symbols.
  3388. * where:                                Backtrace.
  3389. * word:                                 Memory.
  3390. * working directory (of your program):  Working Directory.
  3391. * x:                                    Memory.
  3392.  
  3393.  
  3394. Tag Table:
  3395. Node: Top1027
  3396. Node: License2991
  3397. Node: User Interface16277
  3398. Node: Files19946
  3399. Node: File Arguments20503
  3400. Node: File Commands21222
  3401. Node: Compilation25475
  3402. Node: Running26564
  3403. Node: Arguments28735
  3404. Node: Environment29487
  3405. Node: Working Directory31503
  3406. Node: Input/Output32212
  3407. Node: Attach33517
  3408. Node: Kill Process35108
  3409. Node: Stopping36140
  3410. Node: Signals36947
  3411. Node: Breakpoints40357
  3412. Node: Set Breaks42078
  3413. Node: Delete Breaks45039
  3414. Node: Disabling46427
  3415. Node: Conditions48997
  3416. Node: Break Commands52346
  3417. Node: Error in Breakpoints55814
  3418. Node: Continuing56709
  3419. Node: Stepping58205
  3420. Node: Stack62807
  3421. Node: Frames64228
  3422. Node: Backtrace66667
  3423. Node: Selection68694
  3424. Node: Frame Info70637
  3425. Node: Source72203
  3426. Node: List72885
  3427. Node: Search76501
  3428. Node: Source Path77186
  3429. Node: Data79351
  3430. Node: Expressions80668
  3431. Node: Variables81996
  3432. Node: Arrays83323
  3433. Node: Format options84601
  3434. Node: Output formats86495
  3435. Node: Memory88109
  3436. Node: Auto Display93509
  3437. Node: Value History96226
  3438. Node: Convenience Vars98018
  3439. Node: Registers100207
  3440. Node: Symbols103298
  3441. Node: Altering105913
  3442. Node: Assignment106746
  3443. Node: Jumping108477
  3444. Node: Signaling110899
  3445. Node: Returning111460
  3446. Node: Sequences112605
  3447. Node: Define113068
  3448. Node: Command Files114749
  3449. Node: Output115949
  3450. Node: Options118214
  3451. Node: Mode Options118697
  3452. Node: File Options119925
  3453. Node: Other Arguments120688
  3454. Node: Emacs121066
  3455. Node: Remote123722
  3456. Node: Remote Commands124815
  3457. Node: Commands125635
  3458. Node: Concepts134378
  3459. End Tag Table
  3460.